Skip to content

Commit

Permalink
#443 - publish maven GAVC info into the P2 meta-data
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi authored and mickaelistria committed Jan 4, 2022
1 parent 6fac7dc commit fba2b72
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ public MavenPropertiesAdvice(String groupId, String artifactId, String version,
}
}

public MavenPropertiesAdvice(String groupId, String artifactId, String version, String classifier,
String extension) {
this(groupId, artifactId, version, classifier);
if (extension != null && !extension.isEmpty()) {
properties.put(RepositoryLayoutHelper.PROP_EXTENSION, extension);
}
}

@Override
public Map<String, String> getArtifactProperties(IInstallableUnit iu, IArtifactDescriptor descriptor) {
// workaround Bug 539672
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2021 Christoph Läubrich and others.
* Copyright (c) 2020, 2022 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
Expand Down Expand Up @@ -57,6 +57,7 @@
import org.eclipse.tycho.core.shared.MavenDependenciesResolver;
import org.eclipse.tycho.core.shared.MavenLogger;
import org.eclipse.tycho.core.shared.MavenModelFacade;
import org.eclipse.tycho.p2.impl.publisher.MavenPropertiesAdvice;
import org.eclipse.tycho.p2.metadata.IArtifactFacade;
import org.eclipse.tycho.p2.repository.GAV;
import org.eclipse.tycho.p2.target.TargetDefinitionContent;
Expand Down Expand Up @@ -218,11 +219,14 @@ public MavenTargetDefinitionContent(MavenGAVLocation location, MavenDependencies
logger.debug("The following manifest was generated for this artifact:\r\n"
+ wrappedArtifact.getGeneratedManifest());
}
unit = publish(BundlesAction.createBundleDescription(tempFile), tempFile);
unit = publish(BundlesAction.createBundleDescription(tempFile), tempFile,
/*
* do not propagate maven artifacts info for wrapped bundles
*/ null);
symbolicName = wrappedArtifact.getWrappedBsn();
bundleVersion = wrappedArtifact.getWrappedVersion();
} else {
unit = publish(bundleDescription, bundleLocation);
unit = publish(bundleDescription, bundleLocation, mavenArtifact);
}
bundles.add(unit);
if (logger.isDebugEnabled()) {
Expand Down Expand Up @@ -255,9 +259,11 @@ public MavenTargetDefinitionContent(MavenGAVLocation location, MavenDependencies
}
IInstallableUnit unit;
if (isValidSourceManifest(manifest)) {
unit = publish(BundlesAction.createBundleDescription(sourceFile), sourceFile);
unit = publish(BundlesAction.createBundleDescription(sourceFile), sourceFile,
sourceArtifact);
} else {
unit = generateSourceBundle(symbolicName, bundleVersion, manifest, sourceFile);
unit = generateSourceBundle(symbolicName, bundleVersion, manifest, sourceFile,
sourceArtifact);
}
sourceBundles.add(unit);
if (unit != null && logger.isDebugEnabled()) {
Expand Down Expand Up @@ -320,7 +326,7 @@ public MavenTargetDefinitionContent(MavenGAVLocation location, MavenDependencies
}

private IInstallableUnit generateSourceBundle(String symbolicName, String bundleVersion, Manifest manifest,
File sourceFile) throws IOException, BundleException {
File sourceFile, IArtifactFacade sourceArtifact) throws IOException, BundleException {

File tempFile = File.createTempFile("tycho_wrapped_source", ".jar");
tempFile.deleteOnExit();
Expand Down Expand Up @@ -349,14 +355,21 @@ private IInstallableUnit generateSourceBundle(String symbolicName, String bundle
}
}
}
return publish(BundlesAction.createBundleDescription(tempFile), tempFile);
return publish(BundlesAction.createBundleDescription(tempFile), tempFile, sourceArtifact);

}

private IInstallableUnit publish(BundleDescription bundleDescription, File bundleLocation) {
private IInstallableUnit publish(BundleDescription bundleDescription, File bundleLocation,
IArtifactFacade mavenArtifact) {
IArtifactKey key = BundlesAction.createBundleArtifactKey(bundleDescription.getSymbolicName(),
bundleDescription.getVersion().toString());
PublisherInfo publisherInfo = new PublisherInfo();
if (mavenArtifact != null) {
MavenPropertiesAdvice advice = new MavenPropertiesAdvice(mavenArtifact.getGroupId(),
mavenArtifact.getArtifactId(), mavenArtifact.getVersion(), mavenArtifact.getClassifier(),
mavenArtifact.getPackagingType());
publisherInfo.addAdvice(advice);
}
publisherInfo.setArtifactOptions(IPublisherInfo.A_INDEX);
IInstallableUnit iu = BundlesAction.createBundleIU(bundleDescription, key, publisherInfo);
repositoryContent.put(FileArtifactRepository.forFile(bundleLocation, key), iu);
Expand Down

0 comments on commit fba2b72

Please sign in to comment.