Skip to content

Commit

Permalink
Save work for eclipse-tycho#493 on an extra branch
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Läubrich <[email protected]>
  • Loading branch information
laeubi committed Jan 4, 2022
1 parent d0ae80a commit 7162fed
Show file tree
Hide file tree
Showing 11 changed files with 609 additions and 377 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
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicReference;

Expand All @@ -40,12 +40,10 @@ public class TargetDefinitionResolverService {

private static final String CACHE_MISS_MESSAGE = "Target definition content cache miss: ";

private Map<ResolutionArguments, CompletableFuture<TargetDefinitionContent>> resolutionCache = new ConcurrentHashMap<>();
private ConcurrentMap<ResolutionArguments, CompletableFuture<TargetDefinitionContent>> resolutionCache = new ConcurrentHashMap<>();

private MavenContext mavenContext;

private IProvisioningAgent provisioningAgent;

private final AtomicReference<MavenDependenciesResolver> dependenciesResolver = new AtomicReference<>();

// constructor for DS
Expand All @@ -55,10 +53,22 @@ public TargetDefinitionResolverService() {
public TargetDefinitionContent getTargetDefinitionContent(TargetDefinition definition,
List<TargetEnvironment> environments, ExecutionEnvironmentResolutionHints jreIUs,
IncludeSourceMode includeSourceMode, IProvisioningAgent agent) {
this.provisioningAgent = agent;
ResolutionArguments arguments = new ResolutionArguments(definition, environments, jreIUs, includeSourceMode,
agent);

// synchronized (this) {
// System.out.println("---------------");
// System.out.println(arguments + " = " + arguments.hashCode());
// System.out.println("#arguments.agent =" + arguments.agent.hashCode() + " ("
// + arguments.agent.getClass().getName() + ")");
// System.out.println("#arguments.definition =" + arguments.definition.hashCode() + " ("
// + arguments.definition.getClass().getName() + ")");
// System.out.println("#arguments.environments =" + arguments.environments.hashCode() + " ("
// + arguments.environments.getClass().getName() + ")");
// System.out.println("#arguments.includeSourceMode =" + arguments.includeSourceMode.hashCode() + " ("
// + arguments.includeSourceMode.getClass().getName() + ")");
// System.out.println("#arguments.jreIUs =" + arguments.jreIUs.hashCode() + " ("
// + arguments.jreIUs.getClass().getName() + ")");
// }
CompletableFuture<TargetDefinitionContent> future = resolutionCache.computeIfAbsent(arguments,
this::resolveFromArguments);

Expand All @@ -78,29 +88,33 @@ public TargetDefinitionContent getTargetDefinitionContent(TargetDefinition defin

// this method must only have the cache key as parameter (to make sure that the key is complete)
private CompletableFuture<TargetDefinitionContent> resolveFromArguments(ResolutionArguments arguments) {
if (mavenContext.getLogger().isDebugEnabled()) {
debugCacheMiss(arguments);
mavenContext.getLogger().debug("Resolving target definition content...");
}
mavenContext.getLogger().info("Resolving " + arguments + "...");
// if (mavenContext.getLogger().isDebugEnabled()) {
debugCacheMiss(arguments);
// }

TargetDefinitionResolver resolver = new TargetDefinitionResolver(arguments.environments, arguments.jreIUs,
arguments.includeSourceMode, mavenContext, dependenciesResolver.get());
CompletableFuture<TargetDefinitionContent> future = new CompletableFuture<>();
try {
return CompletableFuture.completedFuture(resolver.resolveContent(arguments.definition, provisioningAgent));
return CompletableFuture.completedFuture(resolver.resolveContent(arguments.definition, arguments.agent));
} catch (Exception e) {
return CompletableFuture.failedFuture(e);
}
}

private void debugCacheMiss(ResolutionArguments arguments) {
if (resolutionCache.isEmpty()) {
System.out.println("cache is empty!");
return;
}

// find cache entries which differ only in one of the arguments
List<String> fieldsInWhichDistanceOneEntriesDiffer = new ArrayList<>();
for (ResolutionArguments existingKey : resolutionCache.keySet()) {
System.out.println("existing: " + existingKey);
List<String> differingFields = arguments.getNonEqualFields(existingKey);
System.out.println(differingFields);
if (differingFields.size() == 1) {
fieldsInWhichDistanceOneEntriesDiffer.add(differingFields.get(0));
}
Expand Down Expand Up @@ -185,6 +199,13 @@ public List<String> getNonEqualFields(ResolutionArguments other) {
return result;
}

@Override
public String toString() {
return "target definition " + definition.getOrigin() + " for environments=" + environments
+ ", include source mode=" + includeSourceMode + ", execution environment=" + jreIUs
+ ", remote p2 repository options=" + agent;
}

}

static <T> boolean eq(T left, T right) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,13 @@ private static Stream<Version> parseEECapabilityVersion(ManifestElement eeCapabi
return Stream.empty();
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("StandardEEResolutionHints [executionEnvironment=");
builder.append(executionEnvironment);
builder.append("]");
return builder.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public interface Location {
}

public interface InstallableUnitLocation extends Location {

public static String TYPE = "InstallableUnit";

public List<? extends Repository> getRepositories();

public List<? extends Unit> getUnits();
Expand All @@ -75,10 +78,17 @@ public interface InstallableUnitLocation extends Location {

public boolean includeSource();

@Override
public default String getTypeDescription() {
return InstallableUnitLocation.TYPE;
}

}

public interface MavenGAVLocation extends Location {

public static final String TYPE = "Maven";

enum MissingManifestStrategy {
IGNORE, ERROR, GENERATE;
}
Expand All @@ -103,6 +113,11 @@ enum DependencyDepth {

Element getFeatureTemplate();

@Override
public default String getTypeDescription() {
return TYPE;
}

}

public interface TargetReferenceLocation extends Location {
Expand Down
Loading

0 comments on commit 7162fed

Please sign in to comment.