use of org.codehaus.plexus.util.xml.Xpp3Dom in project tycho by eclipse.
the class ZipComparatorImpl method getDelta.
@Override
public CompoundArtifactDelta getDelta(File baseline, File reactor, MojoExecution execution) throws IOException {
Map<String, ArtifactDelta> result = new LinkedHashMap<>();
Collection<String> ignoredPatterns = new HashSet<>(IGNORED_PATTERNS);
if (execution != null) {
Xpp3Dom pluginConfiguration = (Xpp3Dom) execution.getPlugin().getConfiguration();
if (pluginConfiguration != null) {
Xpp3Dom ignoredPatternsNode = pluginConfiguration.getChild("ignoredPatterns");
if (ignoredPatternsNode != null) {
for (Xpp3Dom node : ignoredPatternsNode.getChildren()) {
ignoredPatterns.add(node.getValue());
}
}
}
}
ZipFile jar = new ZipFile(baseline);
try {
ZipFile jar2 = new ZipFile(reactor);
try {
Map<String, ZipEntry> entries = toEntryMap(jar, ignoredPatterns);
Map<String, ZipEntry> entries2 = toEntryMap(jar2, ignoredPatterns);
Set<String> names = new TreeSet<>();
names.addAll(entries.keySet());
names.addAll(entries2.keySet());
for (String name : names) {
ZipEntry entry = entries.get(name);
if (entry == null) {
result.put(name, new SimpleArtifactDelta("not present in baseline"));
continue;
}
ZipEntry entry2 = entries2.get(name);
if (entry2 == null) {
result.put(name, new SimpleArtifactDelta("present in baseline only"));
continue;
}
InputStream is = jar.getInputStream(entry);
try {
InputStream is2 = jar2.getInputStream(entry2);
try {
ContentsComparator comparator = comparators.get(getContentType(name));
ArtifactDelta differences = comparator.getDelta(is, is2, execution);
if (differences != null) {
result.put(name, differences);
continue;
}
} finally {
IOUtil.close(is2);
}
} finally {
IOUtil.close(is);
}
}
} finally {
try {
jar2.close();
} catch (IOException e) {
// too bad
}
}
} finally {
try {
jar.close();
} catch (IOException e) {
// ouch
}
}
return !result.isEmpty() ? new CompoundArtifactDelta("different", result) : null;
}
use of org.codehaus.plexus.util.xml.Xpp3Dom in project tycho by eclipse.
the class EclipseInstallationLayout method getSites.
public Set<File> getSites() {
Set<File> result = new LinkedHashSet<>();
if (location == null) {
return result;
}
if (new File(location, PLUGINS).isDirectory()) {
result.add(location);
}
File platform = new File(location, "configuration/org.eclipse.update/platform.xml");
if (platform.canRead()) {
try {
FileInputStream is = new FileInputStream(platform);
try {
XmlStreamReader reader = new XmlStreamReader(is);
Xpp3Dom dom = Xpp3DomBuilder.build(reader);
Xpp3Dom[] sites = dom.getChildren("site");
for (Xpp3Dom site : sites) {
String enabled = site.getAttribute("enabled");
if (enabled == null || Boolean.parseBoolean(enabled)) {
File dir = parsePlatformURL(location, site.getAttribute("url"));
if (dir != null) {
result.add(dir);
}
}
}
} finally {
is.close();
}
} catch (Exception e) {
getLogger().warn("Exception parsing " + toString(platform), e);
}
}
addLinks(result, location, new File(location, "links"));
// deal with dropins folder
result.add(dropinsLocation);
File[] dropinsFiles = dropinsLocation.listFiles();
if (dropinsFiles != null) {
for (File dropinsFile : dropinsFiles) {
File plugins = new File(dropinsFile, PLUGINS);
if (plugins.isDirectory()) {
result.add(plugins.getParentFile());
continue;
}
plugins = new File(dropinsFile, "eclipse/plugins");
if (plugins.isDirectory()) {
result.add(plugins.getParentFile());
}
}
}
addLinks(result, location, dropinsLocation);
return result;
}
use of org.codehaus.plexus.util.xml.Xpp3Dom in project tycho by eclipse.
the class DefaultTargetPlatformConfigurationReader method newTargetEnvironment.
private static TargetEnvironment newTargetEnvironment(Xpp3Dom environmentDom) throws TargetPlatformConfigurationException {
Xpp3Dom osDom = environmentDom.getChild("os");
if (osDom == null) {
String message = "<os> element is missing within target-platform-configuration (element <environment>)";
throw new TargetPlatformConfigurationException(message);
}
Xpp3Dom wsDom = environmentDom.getChild("ws");
if (wsDom == null) {
String message = "<ws> element is missing within target-platform-configuration (element <environment>)";
throw new TargetPlatformConfigurationException(message);
}
Xpp3Dom archDom = environmentDom.getChild("arch");
if (archDom == null) {
String message = "<arch> element is missing within target-platform-configuration (element <environment>)";
throw new TargetPlatformConfigurationException(message);
}
return new TargetEnvironment(osDom.getValue(), wsDom.getValue(), archDom.getValue());
}
use of org.codehaus.plexus.util.xml.Xpp3Dom in project tycho by eclipse.
the class DefaultTargetPlatformConfigurationReader method addTargetEnvironments.
private void addTargetEnvironments(TargetPlatformConfiguration result, MavenProject project, Xpp3Dom configuration) {
try {
TargetEnvironment deprecatedTargetEnvironmentSpec = getDeprecatedTargetEnvironment(configuration);
if (deprecatedTargetEnvironmentSpec != null) {
result.addEnvironment(deprecatedTargetEnvironmentSpec);
}
Xpp3Dom environmentsDom = configuration.getChild("environments");
if (environmentsDom != null) {
if (deprecatedTargetEnvironmentSpec != null) {
String message = "Deprecated target-platform-configuration <environment> element must not be combined with new <environments> element; check the (inherited) configuration of " + project.getId();
throw new RuntimeException(message);
}
for (Xpp3Dom environmentDom : environmentsDom.getChildren("environment")) {
result.addEnvironment(newTargetEnvironment(environmentDom));
}
}
} catch (TargetPlatformConfigurationException e) {
throw new RuntimeException("target-platform-configuration error in project " + project.getId(), e);
}
}
use of org.codehaus.plexus.util.xml.Xpp3Dom in project tycho by eclipse.
the class DefaultTargetPlatformConfigurationReader method addTargetArtifact.
protected void addTargetArtifact(TargetPlatformConfiguration result, MavenSession session, MavenProject project, Xpp3Dom artifactDom) {
Xpp3Dom groupIdDom = artifactDom.getChild("groupId");
Xpp3Dom artifactIdDom = artifactDom.getChild("artifactId");
Xpp3Dom versionDom = artifactDom.getChild("version");
if (groupIdDom == null || artifactIdDom == null || versionDom == null) {
throw new BuildFailureException("The target artifact configuration is invalid - <groupId>, <artifactId> and <version> are mandatory");
}
Xpp3Dom classifierDom = artifactDom.getChild("classifier");
String groupId = groupIdDom.getValue();
String artifactId = artifactIdDom.getValue();
String version = versionDom.getValue();
String classifier = classifierDom != null ? classifierDom.getValue() : null;
File targetFile = null;
for (MavenProject otherProject : session.getProjects()) {
if (groupId.equals(otherProject.getGroupId()) && artifactId.equals(otherProject.getArtifactId()) && version.equals(otherProject.getVersion())) {
String fileName;
if (classifier == null) {
// no classifier means target is provided using packaging type eclipse-target-definition
fileName = artifactId;
} else {
// backward compat for target files manually installed via build-helper-maven-plugin
fileName = classifier;
}
targetFile = new File(otherProject.getBasedir(), fileName + ".target");
break;
}
}
if (targetFile == null) {
Artifact artifact = repositorySystem.createArtifactWithClassifier(groupId, artifactId, version, "target", classifier);
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
request.setArtifact(artifact);
request.setLocalRepository(session.getLocalRepository());
request.setRemoteRepositories(project.getRemoteArtifactRepositories());
repositorySystem.resolve(request);
if (!artifact.isResolved()) {
throw new RuntimeException("Could not resolve target platform specification artifact " + artifact);
}
targetFile = artifact.getFile();
}
result.addTarget(targetFile);
}
Aggregations