-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not use Tycho in eclipse-cbi-plugin
Currently the plugin relies on some of Tycho components and classes this has the risk of breakage and incompatibility. This do the following - drop generate-api-build-xml mojo, if it is useful for anyone it should be migrated to Tycho - remove Tycho dependency - embed relevant portions of Tycho code that are actually used here
- Loading branch information
Showing
10 changed files
with
510 additions
and
371 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
maven-plugins/eclipse-cbi-plugin/src/main/java/org/eclipse/cbi/mojo/DefaultArtifactKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2008, 2011 Sonatype Inc. and others. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Sonatype Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.cbi.mojo; | ||
|
||
import java.util.Objects; | ||
|
||
class DefaultArtifactKey { | ||
private final String type; | ||
|
||
private final String id; | ||
|
||
private final String version; | ||
|
||
public DefaultArtifactKey(String type, String id) { | ||
this(type, id, "0.0.0"); | ||
} | ||
|
||
public DefaultArtifactKey(String type, String id, String version) { | ||
this.id = id; | ||
this.type = type; | ||
this.version = version; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getType(), getId(), getVersion()); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
return this == obj || // | ||
(obj instanceof DefaultArtifactKey other && // | ||
Objects.equals(getType(), other.getType()) && // | ||
Objects.equals(getId(), other.getId()) && // | ||
Objects.equals(getVersion(), other.getVersion())); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getType() + ":" + getId() + ":" + getVersion(); | ||
} | ||
|
||
/** | ||
* @see ProjectType | ||
*/ | ||
public String getType() { | ||
return type; | ||
} | ||
|
||
/** | ||
* Eclipse/OSGi artifact id. Can differ from Maven artifactId. | ||
*/ | ||
public String getId() { | ||
return id; | ||
} | ||
|
||
/** | ||
* Eclipse/OSGi artifact version. Can differ from Maven version. For maven | ||
* projects, this | ||
* version corresponds to version specified in the project sources and does not | ||
* reflect | ||
* qualifier expansion. | ||
*/ | ||
public String getVersion() { | ||
return version; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
maven-plugins/eclipse-cbi-plugin/src/main/java/org/eclipse/cbi/mojo/DefaultBundleReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2008, 2022 Sonatype Inc. and others. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Sonatype Inc. - initial API and implementation | ||
* Christoph Läubrich - Issue #663 - Access to the tycho .cache directory is not properly synchronized | ||
*******************************************************************************/ | ||
package org.eclipse.cbi.mojo; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.jar.JarFile; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipFile; | ||
|
||
class DefaultBundleReader { | ||
|
||
public static OsgiManifest loadManifest(File bundleLocation) { | ||
try { | ||
if (bundleLocation.isDirectory()) { | ||
return loadManifestFromDirectory(bundleLocation); | ||
} else if (bundleLocation.isFile()) { | ||
return loadManifestFromFile(bundleLocation); | ||
} else { | ||
// file does not exist | ||
throw new OsgiManifestParserException(bundleLocation.getAbsolutePath(), "Manifest file not found"); | ||
} | ||
} catch (IOException e) { | ||
throw new OsgiManifestParserException(bundleLocation.getAbsolutePath(), e); | ||
} | ||
} | ||
|
||
private static OsgiManifest loadManifestFromFile(File bundleLocation) throws IOException { | ||
if (!bundleLocation.getName().toLowerCase().endsWith(".jar")) { | ||
// file but not a jar, assume it is MANIFEST.MF | ||
return loadManifestFile(bundleLocation); | ||
} | ||
try ( // it is a jar, let's see if it has OSGi bundle manifest | ||
ZipFile jar = new ZipFile(bundleLocation, ZipFile.OPEN_READ)) { | ||
ZipEntry manifestEntry = jar.getEntry(JarFile.MANIFEST_NAME); | ||
if (manifestEntry != null) { | ||
InputStream stream = jar.getInputStream(manifestEntry); | ||
return new OsgiManifest(stream, bundleLocation.getAbsolutePath() + "!/" + JarFile.MANIFEST_NAME); | ||
} | ||
} | ||
throw new OsgiManifestParserException(bundleLocation.getAbsolutePath(), | ||
"Manifest file not found in JAR archive"); | ||
} | ||
|
||
private static OsgiManifest loadManifestFromDirectory(File directory) throws IOException { | ||
File manifestFile = new File(directory, JarFile.MANIFEST_NAME); | ||
if (!manifestFile.isFile()) { | ||
throw new OsgiManifestParserException(manifestFile.getAbsolutePath(), "Manifest file not found"); | ||
} | ||
return loadManifestFile(manifestFile); | ||
} | ||
|
||
private static OsgiManifest loadManifestFile(File manifestFile) throws IOException, OsgiManifestParserException { | ||
return new OsgiManifest(new FileInputStream(manifestFile), manifestFile.getAbsolutePath()); | ||
} | ||
|
||
} |
Oops, something went wrong.