Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbeaver/dbeaver-infra#161 model refactoring #1

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#################
## Misc

bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
.settings
local.properties
.loadpath

# External tool builders
.externalToolBuilders/

## Maven stuff

target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
/workspace/

## IDEA configs

*.iml
/idea/

## Eclipse configs

.project
.classpath
.settings/

## Eclipse PDE
*.product.launch

# Dev executables

.cmd
.bat

#############
## Windows detritus
#############

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Mac crap
.DS_Store
54 changes: 54 additions & 0 deletions osgi/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.dbeaver.osgi</groupId>
<artifactId>osgi-common</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>osgi</artifactId>
<packaging>jar</packaging>
<version>1.0.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
</build>
<dependencies>
<dependency>
<groupId>com.dbeaver.common</groupId>
<artifactId>org.jkiss.utils</artifactId>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.14</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.4</version>
</dependency>
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>4.7.3</version>
</dependency>
</dependencies>
</project>
23 changes: 23 additions & 0 deletions osgi/src/main/java/com/dbeaver/osgi/Artifact.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dbeaver.osgi;

import com.dbeaver.osgi.util.Version;

public record Artifact(String classifier, String id, Version version) {

}
211 changes: 211 additions & 0 deletions osgi/src/main/java/com/dbeaver/osgi/BundleInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dbeaver.osgi;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import org.jkiss.code.NotNull;
import com.dbeaver.osgi.util.Version;
import com.dbeaver.osgi.util.VersionRange;
import org.jkiss.utils.Pair;

import java.nio.file.Path;
import java.util.*;

public class BundleInfo implements ModuleInfo {

public static String currentOS;
public static String currentWS;
public static String currentArch;

static {
String osName = System.getProperty("os.name", "generic");
if (osName == null) {
osName = "Windows";
}
osName = osName.toLowerCase(Locale.ENGLISH);

String arch = System.getProperty("os.arch");
if (arch == null || arch.equals("amd64")) {
arch = "x86_64";
} else if (arch.equals("arm64")) {
arch = "aarch64";
}

BundleInfo.currentArch = arch;
if ((osName.contains("mac")) || (osName.contains("darwin"))) {
BundleInfo.currentOS = "macosx";
BundleInfo.currentWS = "cocoa";
} else if (osName.contains("win")) {
BundleInfo.currentOS = "win32";
BundleInfo.currentWS = "win32";
} else {
BundleInfo.currentOS = "linux";
BundleInfo.currentWS = "gtk";
}
}

private final List<String> requireFragments;

protected Set<String> reexportedBundles;
protected Pair<String, VersionRange> fragmentHost;
@NotNull
protected Path path;
private final String bundleName;
private final String bundleVersion;
protected List<String> classpathLibs;
private final List<Pair<String, VersionRange>> requireBundles;
private final Set<Pair<String, Version>> exportPackages;
private final Set<Pair<String, VersionRange>> importPackages;
private final Integer startLevel;
// Additional versions is an exceptional case
// E.g. jakarta.annotation-api of different versions (1.x and 2.x) are completely different and export different packages
// Thus we need all versions
private String additionalVersions;
private final Set<BundleInfo> fragments = new HashSet<>();

public BundleInfo(
@Nullable Path path,
@Nonnull String bundleName,
@Nonnull String bundleVersion,
@Nonnull List<String> classpathLibs,
@Nonnull List<Pair<String, VersionRange>> requireBundles,
@Nonnull Set<String> reexportedBundles,
@Nonnull Set<Pair<String, Version>> exportPackages,
@Nonnull Set<Pair<String, VersionRange>> importPackages,
@Nonnull List<String> requiredFragments,
@Nullable Pair<String, VersionRange> fragmentHost,
@Nullable Integer startLevel) {
this.path = path;
this.bundleName = bundleName;
this.bundleVersion = bundleVersion;
this.classpathLibs = classpathLibs;
this.requireBundles = requireBundles;
this.reexportedBundles = reexportedBundles;
this.exportPackages = exportPackages;
this.importPackages = importPackages;
this.startLevel = startLevel;
this.fragmentHost = fragmentHost;
this.requireFragments = requiredFragments;
}

public @Nullable Path getPath() {
return path;
}

public @Nonnull String getBundleName() {
return bundleName;
}

public @Nonnull String getBundleVersion() {
return bundleVersion;
}

public @Nonnull List<String> getClasspathLibs() {
return classpathLibs;
}

public @Nonnull List<Pair<String, VersionRange>> getRequireBundles() {
return requireBundles;
}

public @Nonnull Set<Pair<String, Version>> getExportPackages() {
return exportPackages;
}

public @Nonnull Set<String> getReexportedBundles() {
return reexportedBundles;
}

public @Nonnull Set<Pair<String, VersionRange>> getImportPackages() {
return importPackages;
}

public @Nullable Pair<String, VersionRange> getFragmentHost() {
return fragmentHost;
}

public Set<BundleInfo> getFragments() {
return fragments;
}

public List<String> getRequireFragments() {
return requireFragments;
}

public @Nullable Integer getStartLevel() {
return startLevel;
}

@Nullable
public String getAdditionalVersions() {
return additionalVersions;
}

public void addAdditionalVersion(@Nonnull String version) {
if (additionalVersions == null) {
additionalVersions = version;
} else {
if (!additionalVersions.contains(version)) {
additionalVersions += "," + version;
}
}
}

public void addFragmentBundle(BundleInfo fragment) {
this.fragments.add(fragment);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
BundleInfo that = (BundleInfo) o;
return Objects.equals(getPath(), that.getPath()) &&
Objects.equals(getBundleName(), that.getBundleName()) &&
Objects.equals(getBundleVersion(), that.getBundleVersion()) &&
Objects.equals(getClasspathLibs(), that.getClasspathLibs()) &&
Objects.equals(getRequireBundles(), that.getRequireBundles()) &&
Objects.equals(getExportPackages(), that.getExportPackages()) &&
Objects.equals(getImportPackages(), that.getImportPackages()) &&
Objects.equals(getStartLevel(), that.getStartLevel());
}

@Override
public int hashCode() {
return Objects.hash(getPath(), getBundleName(), getBundleVersion(), getClasspathLibs(), getRequireBundles(), getExportPackages(), getImportPackages(), getStartLevel());
}

@Override
public String toString() {
return "BundleInfo[" + bundleName + "]";
}

@Override
public String getModuleName() {
return getBundleName();
}

@Override
public Path getModuleFile() {
return getPath();
}
}
Loading