Skip to content

Commit

Permalink
Bug 569146 - Add support for exploded bundles in file-based target
Browse files Browse the repository at this point in the history
platform

- Support transferring of exploded bundles via FileArtifactRepository
- Add integrationtest for Directory based Target platforms with exploded
bundles

Change-Id: I6b89b368a9873d8c48ebcb375d31a35f1e01c5c5
Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
  • Loading branch information
laeubi committed Nov 25, 2020
1 parent 8aa686b commit e8e6e5c
Show file tree
Hide file tree
Showing 14 changed files with 255 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@
package org.eclipse.tycho.p2.target.repository;

import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
import java.nio.file.attribute.FileTime;
import java.util.Iterator;
import java.util.function.Supplier;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
Expand Down Expand Up @@ -60,15 +67,52 @@ public IStatus getRawArtifact(IArtifactDescriptor descriptor, OutputStream desti
return new Status(IStatus.ERROR, FileTargetDefinitionContent.class.getName(), "Artifact not found");
}
try {
try (FileInputStream inputStream = new FileInputStream(artifactFile)) {
inputStream.transferTo(destination);
if (artifactFile.isDirectory()) {
File manifestFile = new File(artifactFile, JarFile.MANIFEST_NAME);
try (JarOutputStream jarOutputStream = new JarOutputStream(destination)) {
if (manifestFile.exists()) {
Manifest manifest = new Manifest(new FileInputStream(manifestFile));
manifest.getMainAttributes().putValue("Eclipse-BundleShape", "dir");
jarOutputStream.putNextEntry(new ZipEntry(JarFile.MANIFEST_NAME));
manifest.write(jarOutputStream);
jarOutputStream.closeEntry();
}
copyToStream(artifactFile, jarOutputStream, null, f -> !f.equals(manifestFile));
}
} else {
try (FileInputStream inputStream = new FileInputStream(artifactFile)) {
inputStream.transferTo(destination);
}
}
} catch (IOException e) {
return new Status(IStatus.ERROR, FileTargetDefinitionContent.class.getName(), "transfer failed", e);
}
return Status.OK_STATUS;
}

private void copyToStream(File file, ZipOutputStream os, String path, FileFilter fileFilter) throws IOException {
String pathName = path == null ? "" : path + file.getName();
if (file.isFile()) {
try (FileInputStream is = new FileInputStream(file)) {
ZipEntry entry = new ZipEntry(pathName);
entry.setLastModifiedTime(FileTime.fromMillis(file.lastModified()));
os.putNextEntry(entry);
is.transferTo(os);
os.closeEntry();
}
} else if (file.isDirectory()) {
File[] files = file.listFiles(fileFilter);
if (files != null && files.length > 0) {
for (File file2 : files) {
copyToStream(file2, os, pathName + "/", fileFilter);
}
}
} else {
throw new IOException(
"file " + file.getAbsolutePath() + " is neither a readable file nor a readable directory");
}
}

@Override
public IQueryable<IArtifactDescriptor> descriptorQueryable() {
return (query, monitor) -> query.perform(descriptorSupplier.get());
Expand Down
17 changes: 17 additions & 0 deletions tycho-its/projects/target.directory/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>target.directory</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
63 changes: 63 additions & 0 deletions tycho-its/projects/target.directory/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- - Copyright (c) 2015, 2020 SAP SE and others. - All rights reserved. This
program and the accompanying materials - are made available under the terms
of the Eclipse Public License v1.0 - which accompanies this distribution,
and is available at - http://www.eclipse.org/legal/epl-v10.html - - Contributors:
- SAP SE - initial API and implementation -->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.eclipse.tycho.itests</groupId>
<artifactId>testparent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>


<pluginRepositories>
<pluginRepository>
<id>tycho-snapshots</id>
<url>${tycho-snapshots-url}</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

<modules>
<module>target.test</module>
<module>test.directory.bundle</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<target>
<artifact>
<groupId>org.eclipse.tycho.itests</groupId>
<artifactId>target-definition</artifactId>
<version>0.0.1-SNAPSHOT</version>
</artifact>
</target>
</configuration>
</plugin>
</plugins>
</build>



</project>
17 changes: 17 additions & 0 deletions tycho-its/projects/target.directory/target.test/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>target.test</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Bundle
Bundle-SymbolicName: directory.bundle
Bundle-Version: 0.0.1
Bundle-RequiredExecutionEnvironment: J2SE-1.5

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin.includes = META-INF/
21 changes: 21 additions & 0 deletions tycho-its/projects/target.directory/target.test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012 SAP AG All rights reserved. This program
and the accompanying materials are made available under the terms of
the Eclipse Public License v1.0 which accompanies this distribution,
and is available at http://www.eclipse.org/legal/epl-v10.html
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>target-definition</artifactId>
<packaging>eclipse-target-definition</packaging>

<parent>
<groupId>org.eclipse.tycho.itests</groupId>
<artifactId>testparent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
28 changes: 28 additions & 0 deletions tycho-its/projects/target.directory/test.directory.bundle/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>test.directory.bundle</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=11
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Bundle
Bundle-SymbolicName: test.directory.bundle
Bundle-Version: 0.0.1.qualifier
Automatic-Module-Name: test.bundle
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: directory.bundle;bundle-version="0.0.1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
21 changes: 21 additions & 0 deletions tycho-its/projects/target.directory/test.directory.bundle/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012 SAP AG All rights reserved. This program
and the accompanying materials are made available under the terms of
the Eclipse Public License v1.0 which accompanies this distribution,
and is available at http://www.eclipse.org/legal/epl-v10.html
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>test.directory.bundle</artifactId>
<packaging>eclipse-plugin</packaging>

<parent>
<groupId>org.eclipse.tycho.itests</groupId>
<artifactId>testparent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ public void testMavenLocation() throws Exception {
verifier.verifyErrorFreeLog();
}

public void testDirectoryLocation() throws Exception {
Verifier verifier = getVerifier("target.directory", false, true);
verifier.executeGoal("verify");
verifier.verifyErrorFreeLog();
}

}

0 comments on commit e8e6e5c

Please sign in to comment.