Skip to content

Commit

Permalink
Merge pull request #417 from laeubi/issue_401
Browse files Browse the repository at this point in the history
Fix #401 - Support nested targets
  • Loading branch information
laeubi authored Dec 8, 2021
2 parents 0a21968 + 981d4b0 commit 5311241
Show file tree
Hide file tree
Showing 18 changed files with 328 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -60,6 +61,8 @@
import org.eclipse.tycho.p2.target.facade.TargetDefinition.PathLocation;
import org.eclipse.tycho.p2.target.facade.TargetDefinition.ProfileLocation;
import org.eclipse.tycho.p2.target.facade.TargetDefinition.Repository;
import org.eclipse.tycho.p2.target.facade.TargetDefinition.TargetReferenceLocation;
import org.eclipse.tycho.p2.target.facade.TargetDefinitionFile;
import org.eclipse.tycho.p2.target.facade.TargetDefinitionResolutionException;
import org.eclipse.tycho.p2.target.facade.TargetDefinitionSyntaxException;
import org.eclipse.tycho.p2.util.resolution.ExecutionEnvironmentResolutionHints;
Expand Down Expand Up @@ -148,10 +151,18 @@ TargetDefinitionContent resolveContentWithExceptions(TargetDefinition definition
installableUnitResolver.addLocation((InstallableUnitLocation) locationDefinition, locationUnits);
} else if (locationDefinition instanceof PathLocation) {
PathLocation pathLocation = (PathLocation) locationDefinition;
File path = resolvePath(pathLocation.getPath(), definition);
if (path.exists()) {

String resolvePath = resolvePath(pathLocation.getPath(), definition);
File fileLocation;
try {
fileLocation = new File(resolvePath).getCanonicalFile();
} catch (IOException e) {
throw new ResolverException("I/O Error while resolving path " + resolvePath, e);
}
if (fileLocation.exists()) {
FileTargetDefinitionContent fileRepositoryRolver = fileRepositories.computeIfAbsent(
path.getAbsolutePath(), key -> new FileTargetDefinitionContent(provisioningAgent, path));
fileLocation.getAbsolutePath(),
key -> new FileTargetDefinitionContent(provisioningAgent, fileLocation));
if (pathLocation instanceof DirectoryLocation || pathLocation instanceof ProfileLocation) {
unitResultSet.addAll(
fileRepositoryRolver.query(QueryUtil.ALL_UNITS, new LoggingProgressMonitor(logger)));
Expand All @@ -165,8 +176,8 @@ TargetDefinitionContent resolveContentWithExceptions(TargetDefinition definition
new LoggingProgressMonitor(logger)));
}
} else {
logger.warn("Target location path '" + path.getAbsolutePath()
+ "' does not exist, target resoloution might be incomplete.");
logger.warn("Target location path '" + fileLocation.getAbsolutePath()
+ "' does not exist, target resolution might be incomplete.");
}
} else if (locationDefinition instanceof MavenGAVLocation) {
MavenGAVLocation location = (MavenGAVLocation) locationDefinition;
Expand All @@ -182,6 +193,22 @@ TargetDefinitionContent resolveContentWithExceptions(TargetDefinition definition
logger.debug("\t" + iu);
}
}
} else if (locationDefinition instanceof TargetReferenceLocation) {
TargetReferenceLocation referenceLocation = (TargetReferenceLocation) locationDefinition;
logger.info("Resolving " + referenceLocation.getUri());
String resolvePath = resolvePath(referenceLocation.getUri(), definition);
URI resolvedUri;
try {
resolvedUri = new URI(resolvePath);
} catch (URISyntaxException e) {
throw new ResolverException("Invalid URI " + resolvePath + ": " + e.getMessage(), e);
}
logger.info("Reading target " + resolvedUri + "...");
TargetDefinitionContent content = resolveContentWithExceptions(TargetDefinitionFile.read(resolvedUri),
provisioningAgent);
IQueryResult<IInstallableUnit> result = content.query(QueryUtil.ALL_UNITS,
new LoggingProgressMonitor(logger));
unitResultSet.addAll(result);
} else {
logger.warn("Target location type '" + locationDefinition.getTypeDescription() + "' is not supported");
}
Expand Down Expand Up @@ -247,38 +274,43 @@ public IArtifactRepository getArtifactRepository() {
};
}

protected File resolvePath(String path, TargetDefinition definition) throws ResolverException {
protected String resolvePath(String path, TargetDefinition definition) {
path = resolvePattern(path, SYSTEM_PROPERTY_PATTERN,
key -> mavenContext.getSessionProperties().getProperty(key, ""));
path = resolvePattern(path, ENV_VAR_PATTERN, key -> {
String env = System.getenv(key);
return env == null ? "" : env;
});
path = resolvePattern(path, PROJECT_LOC_PATTERN, this::findProjectLocation);
try {
return new File(path).getCanonicalFile();
} catch (IOException e) {
throw new ResolverException("I/O Error while resolve path " + path, e);
}
return path;
}

private String findProjectLocation(String projectName) {
if (projectName.startsWith("/")) {
projectName = projectName.substring(1);
}
logger.debug("Find project location for project " + projectName);
for (ReactorProject project : mavenContext.getProjects()) {
if (project.getName().equals(projectName)) {
String name = project.getName();
logger.debug("check reactor project name: " + name);
if (name.equals(projectName)) {
return project.getBasedir().getAbsolutePath();
}
}
for (ReactorProject project : mavenContext.getProjects()) {
if (project.getArtifactId().equals(projectName)) {
String artifactId = project.getArtifactId();
logger.debug("check reactor project artifact id: " + artifactId);
if (artifactId.equals(projectName)) {
return project.getBasedir().getAbsolutePath();
}
}
for (ReactorProject project : mavenContext.getProjects()) {
if (project.getBasedir().getName().equals(projectName)) {
String name = project.getBasedir().getName();
logger.debug("check reactor project base directory: " + name);
if (name.equals(projectName)) {
return project.getBasedir().getAbsolutePath();
}
}

//if we can't resolve this, we will return the original one as this might be intentional to not include the project in the build
String defaultValue = "${project_loc:" + projectName + "}";
logger.warn("Can't resolve " + defaultValue + " target resoloution might be incomplete");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ Import-Package: org.eclipse.tycho,
org.eclipse.tycho.artifacts,
org.eclipse.tycho.core.ee.shared,
org.eclipse.tycho.core.resolver.shared,
org.eclipse.tycho.core.shared
org.eclipse.tycho.core.shared,
org.w3c.dom
Automatic-Module-Name: org.eclipse.tycho.p2.resolver.shared
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
* [Bug 568729] - Support new "Maven" Target location
* [Bug 569481] - Support for maven target location includeSource="true" attribute
* [Issue 189] - Support multiple maven-dependencies for one target location
* [Issue 194] - Support additional repositories defined in the maven-target location #
* [Issue 194] - Support additional repositories defined in the maven-target location
* [Issue 401] - Support nested targets
*******************************************************************************/
package org.eclipse.tycho.p2.target.facade;

Expand Down Expand Up @@ -94,6 +95,10 @@ enum MissingManifestStrategy {
boolean includeSource();
}

public interface TargetReferenceLocation extends Location {
String getUri();
}

/**
* Represents the "Directory" location that either contains bundles directly or has
* plugins/features/binaries folders that contains the data
Expand Down
Loading

0 comments on commit 5311241

Please sign in to comment.