Skip to content

Commit

Permalink
Add an organize-manifest mojo
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Jan 29, 2024
1 parent 98123cb commit 4227b8e
Show file tree
Hide file tree
Showing 17 changed files with 376 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Contributors:
* SAP SE - initial API and implementation
*******************************************************************************/
package org.eclipse.tycho.core.resolver.target;
package org.eclipse.tycho;

import static org.eclipse.tycho.ArtifactType.TYPE_BUNDLE_FRAGMENT;
import static org.eclipse.tycho.ArtifactType.TYPE_ECLIPSE_FEATURE;
Expand All @@ -24,20 +24,14 @@
import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.metadata.VersionRange;
import org.eclipse.equinox.p2.publisher.eclipse.BundlesAction;
import org.eclipse.equinox.p2.query.IQuery;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.equinox.spi.p2.publisher.PublisherHelper;
import org.eclipse.tycho.ArtifactKey;
import org.eclipse.tycho.ArtifactType;
import org.eclipse.tycho.DefaultArtifactKey;
import org.eclipse.tycho.IArtifactFacade;
import org.eclipse.tycho.IllegalArtifactReferenceException;
import org.eclipse.tycho.PackagingType;

public class ArtifactTypeHelper {

// p2 installable units
public static final String CAPABILITY_NS_OSGI_BUNDLE = "osgi.bundle"; //see org.eclipse.equinox.p2.publisher.eclipse.BundlesAction.CAPABILITY_NS_OSGI_BUNDLE
public static final String OSGI_BUNDLE_CLASSIFIER = "osgi.bundle"; //see org.eclipse.equinox.p2.publisher.eclipse.BundlesAction.OSGI_BUNDLE_CLASSIFIER

/**
* Returns a query matching the installable units representing the specified Eclipse
Expand Down Expand Up @@ -90,8 +84,7 @@ public static IRequirement createRequirementFor(String type, String id, VersionR
}

private static IRequirement createBundleRequirement(String id, VersionRange versionRange) {
return MetadataFactory.createRequirement(BundlesAction.CAPABILITY_NS_OSGI_BUNDLE, id, versionRange, null, false,
true); // optional=false, multiple=true
return MetadataFactory.createRequirement(CAPABILITY_NS_OSGI_BUNDLE, id, versionRange, null, false, true); // optional=false, multiple=true
}

private static IRequirement createFeatureRequirement(String id, VersionRange versionRange) {
Expand Down Expand Up @@ -187,4 +180,8 @@ public static String getType(IArtifactFacade artifactFacade) {
return ArtifactType.TYPE_INSTALLABLE_UNIT;
}

public static boolean isBundle(IArtifactKey key) {
return key != null && OSGI_BUNDLE_CLASSIFIER.equals(key.getClassifier());
}

}
17 changes: 17 additions & 0 deletions tycho-api/src/main/java/org/eclipse/tycho/TargetPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
package org.eclipse.tycho;

import java.io.File;
import java.util.stream.Stream;

import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.VersionRange;
import org.eclipse.equinox.p2.query.IQuery;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.spi.p2.publisher.PublisherHelper;
Expand Down Expand Up @@ -89,6 +94,18 @@ default ResolvedArtifactKey resolvePackage(String packageName, String versionRef
location);
}

default Stream<ArtifactKey> resolvePackages(String packageName, VersionRange versionRange) {
IQuery<IInstallableUnit> query = ArtifactTypeHelper.createQueryFor(PublisherHelper.CAPABILITY_NS_JAVA_PACKAGE,
packageName, versionRange);
IQueryResult<IInstallableUnit> result = getMetadataRepository().query(query, null);
return result.stream().flatMap(iu -> {
return iu.getArtifacts().stream().filter(key -> ArtifactTypeHelper.isBundle(key)).map(key -> {
return new DefaultArtifactKey(ArtifactType.TYPE_ECLIPSE_PLUGIN, key.getId(),
key.getVersion().toString());
});
});
}

/**
* @return the target platform content as a {@link IMetadataRepository}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.tycho.ArtifactKey;
import org.eclipse.tycho.ArtifactTypeHelper;
import org.eclipse.tycho.DefaultArtifactKey;
import org.eclipse.tycho.DependencyArtifacts;
import org.eclipse.tycho.PackagingType;
Expand All @@ -32,7 +33,6 @@
import org.eclipse.tycho.core.ArtifactDependencyWalker;
import org.eclipse.tycho.core.TychoProject;
import org.eclipse.tycho.core.osgitools.targetplatform.DefaultDependencyArtifacts;
import org.eclipse.tycho.core.resolver.target.ArtifactTypeHelper;
import org.eclipse.tycho.model.Feature;
import org.eclipse.tycho.targetplatform.P2TargetPlatform;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.tycho.ArtifactKey;
import org.eclipse.tycho.ArtifactType;
import org.eclipse.tycho.ArtifactTypeHelper;
import org.eclipse.tycho.DefaultArtifactKey;
import org.eclipse.tycho.core.resolver.target.ArtifactTypeHelper;
import org.eclipse.tycho.p2.resolver.ClassifiedArtifactKey;
import org.eclipse.tycho.p2.resolver.ClassifiedLocation;
import org.eclipse.tycho.targetplatform.P2TargetPlatform;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.equinox.spi.p2.publisher.PublisherHelper;
import org.eclipse.tycho.ArtifactTypeHelper;
import org.eclipse.tycho.IllegalArtifactReferenceException;

public class ArtifactMatcher {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.tycho.ArtifactKey;
import org.eclipse.tycho.ArtifactType;
import org.eclipse.tycho.ArtifactTypeHelper;
import org.eclipse.tycho.BuildFailureException;
import org.eclipse.tycho.DependencySeed;
import org.eclipse.tycho.Interpolator;
import org.eclipse.tycho.core.resolver.target.ArtifactTypeHelper;
import org.eclipse.tycho.core.shared.MavenLogger;
import org.eclipse.tycho.p2.repository.PublishingRepository;
import org.eclipse.tycho.p2.tools.publisher.facade.PublishProductTool;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.tycho.ArtifactKey;
import org.eclipse.tycho.ArtifactType;
import org.eclipse.tycho.ArtifactTypeHelper;
import org.eclipse.tycho.DefaultArtifactKey;
import org.eclipse.tycho.DependencyResolutionException;
import org.eclipse.tycho.ExecutionEnvironmentConfiguration;
Expand All @@ -66,7 +67,6 @@
import org.eclipse.tycho.core.resolver.P2ResolutionResult;
import org.eclipse.tycho.core.resolver.P2Resolver;
import org.eclipse.tycho.core.resolver.shared.PomDependencies;
import org.eclipse.tycho.core.resolver.target.ArtifactTypeHelper;
import org.eclipse.tycho.core.shared.LoggingProgressMonitor;
import org.eclipse.tycho.core.shared.MavenLogger;
import org.eclipse.tycho.core.shared.MultiLineLogger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
import org.eclipse.tycho.ArtifactKey;
import org.eclipse.tycho.ArtifactType;
import org.eclipse.tycho.ArtifactTypeHelper;
import org.eclipse.tycho.DefaultArtifactKey;
import org.eclipse.tycho.IArtifactFacade;
import org.eclipse.tycho.IRawArtifactFileProvider;
import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.TychoConstants;
import org.eclipse.tycho.core.resolver.target.ArtifactTypeHelper;
import org.eclipse.tycho.core.resolver.target.FileArtifactRepository;
import org.eclipse.tycho.p2.repository.ArtifactTransferPolicies;
import org.eclipse.tycho.p2.repository.FileRepositoryArtifactProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.metadata.VersionRange;
import org.eclipse.tycho.ArtifactType;
import org.eclipse.tycho.ArtifactTypeHelper;
import org.eclipse.tycho.DefaultArtifactKey;
import org.eclipse.tycho.DependencyResolutionException;
import org.eclipse.tycho.ExecutionEnvironmentResolutionHints;
Expand All @@ -34,7 +35,6 @@
import org.eclipse.tycho.IllegalArtifactReferenceException;
import org.eclipse.tycho.ReactorProjectIdentities;
import org.eclipse.tycho.core.resolver.target.ArtifactMatcher;
import org.eclipse.tycho.core.resolver.target.ArtifactTypeHelper;
import org.eclipse.tycho.p2.repository.LocalArtifactRepository;
import org.eclipse.tycho.targetplatform.P2TargetPlatform;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.tycho.ArtifactTypeHelper;
import org.eclipse.tycho.ExecutionEnvironmentConfiguration;
import org.eclipse.tycho.ExecutionEnvironmentResolutionHints;
import org.eclipse.tycho.IArtifactFacade;
Expand All @@ -84,7 +85,6 @@
import org.eclipse.tycho.core.osgitools.MavenBundleResolver;
import org.eclipse.tycho.core.osgitools.OsgiBundleProject;
import org.eclipse.tycho.core.resolver.shared.ReferencedRepositoryMode;
import org.eclipse.tycho.core.resolver.target.ArtifactTypeHelper;
import org.eclipse.tycho.core.resolver.target.DuplicateReactorIUsException;
import org.eclipse.tycho.core.resolver.target.FileArtifactRepository;
import org.eclipse.tycho.core.resolver.target.TargetPlatformFilterEvaluator;
Expand Down
4 changes: 4 additions & 0 deletions tycho-extras/tycho-dependency-tools-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-core</artifactId>
</dependency>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bndlib</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*******************************************************************************
* Copyright (c) 2023 Christoph Läubrich 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
*******************************************************************************/
package org.eclipse.tycho.extras.pde;

public class ExportedPackages {

public ExportedPackages(String manifestValue) {
// TODO Auto-generated constructor stub
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*******************************************************************************
* Copyright (c) 2023 Christoph Läubrich 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
*******************************************************************************/
package org.eclipse.tycho.extras.pde;

import org.osgi.framework.Constants;

import aQute.bnd.header.Attrs;

public class ImportedPackage {

private ImportedPackages packages;
private String packageName;
private Attrs attrs;

public ImportedPackage(ImportedPackages packages, String packageName, Attrs attrs) {
this.packages = packages;
this.packageName = packageName;
this.attrs = attrs;
}

public String getPackageName() {
return packageName;
}

public String getVersion() {
return attrs.get(Constants.VERSION_ATTRIBUTE);
}

public boolean isJava() {
return packageName.startsWith("java.");
}

@Override
public String toString() {
String version = getVersion();
if (version != null) {
return getPackageName() + " " + version;
}
return getPackageName();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2023 Christoph Läubrich 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
*******************************************************************************/
package org.eclipse.tycho.extras.pde;

import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.stream.Stream;

import aQute.bnd.header.Attrs;
import aQute.bnd.header.OSGiHeader;
import aQute.bnd.header.Parameters;

public class ImportedPackages {

//import package order is not important so we can sort here by name
private Map<String, ImportedPackage> packages = new TreeMap<>();

public ImportedPackages(String manifestValue) {
if (manifestValue != null) {
Parameters header = OSGiHeader.parseHeader(manifestValue);
for (Entry<String, Attrs> entry : header.entrySet()) {
packages.put(entry.getKey(), new ImportedPackage(this, entry.getKey(), entry.getValue()));
}
}
}

public Stream<ImportedPackage> packages() {
return packages.values().stream();

}

}
Loading

0 comments on commit 4227b8e

Please sign in to comment.