Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bp warning fix #3124

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,26 @@

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;

import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactDescriptor;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.publisher.IPublisherAdvice;
import org.eclipse.equinox.p2.publisher.PublisherInfo;
import org.eclipse.equinox.p2.publisher.actions.IPropertyAdvice;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor;
import org.eclipse.equinox.spi.p2.publisher.PublisherHelper;
import org.eclipse.tycho.TychoConstants;
import org.eclipse.tycho.p2.metadata.IP2Artifact;
Expand All @@ -41,11 +43,19 @@
import org.eclipse.tycho.p2maven.advices.MavenPropertiesAdvice;

public class FeatureRootfileArtifactRepository extends TransientArtifactRepository {
//for backward compatibility
@SuppressWarnings("deprecation")
private static final String PROP_EXTENSION = TychoConstants.PROP_EXTENSION;

private final File outputDirectory;

private final PublisherInfo publisherInfo;

private Map<String, IP2Artifact> publishedArtifacts = new HashMap<>();
private Map<File, IArtifactKey> artifactsToPublish = new HashMap<>();

private Map<String, IP2Artifact> collect;

private List<IArtifactDescriptor> temp = new ArrayList<>();

public FeatureRootfileArtifactRepository(PublisherInfo publisherInfo, File outputDirectory) {
this.publisherInfo = publisherInfo;
Expand All @@ -56,8 +66,18 @@ public FeatureRootfileArtifactRepository(PublisherInfo publisherInfo, File outpu
public OutputStream getOutputStream(IArtifactDescriptor descriptor) throws ProvisionException {
IArtifactKey artifactKey = descriptor.getArtifactKey();
if (artifactKey != null && PublisherHelper.BINARY_ARTIFACT_CLASSIFIER.equals(artifactKey.getClassifier())) {
if (!publisherInfo
.getAdvice(null, false, artifactKey.getId(), artifactKey.getVersion(), IPropertyAdvice.class)
.stream().anyMatch(advice -> advice instanceof MavenPropertiesAdvice)) {
throw new ProvisionException("MavenPropertiesAdvice does not exist for artifact: " + artifactKey);
}
File outputFile = new File(this.outputDirectory, artifactKey.getId() + "-" + artifactKey.getVersion() + "-"
+ TychoConstants.ROOTFILE_CLASSIFIER + "." + TychoConstants.ROOTFILE_EXTENSION);
try {
return createRootfileOutputStream(artifactKey);
temp.add(descriptor);
descriptors.add(descriptor);
artifactsToPublish.put(outputFile, artifactKey);
return new BufferedOutputStream(new FileOutputStream(outputFile));
} catch (IOException e) {
throw new ProvisionException(e.getMessage(), e);
}
Expand All @@ -66,52 +86,6 @@ public OutputStream getOutputStream(IArtifactDescriptor descriptor) throws Provi
return super.getOutputStream(descriptor);
}

private OutputStream createRootfileOutputStream(IArtifactKey artifactKey) throws ProvisionException, IOException {
File outputFile = new File(this.outputDirectory, artifactKey.getId() + "-" + artifactKey.getVersion() + "-"
+ TychoConstants.ROOTFILE_CLASSIFIER + "." + TychoConstants.ROOTFILE_EXTENSION);

OutputStream target = null;
try {
SimpleArtifactDescriptor simpleArtifactDescriptor = (SimpleArtifactDescriptor) createArtifactDescriptor(
artifactKey);

Collection<IPropertyAdvice> advices = publisherInfo.getAdvice(null, false,
simpleArtifactDescriptor.getArtifactKey().getId(),
simpleArtifactDescriptor.getArtifactKey().getVersion(), IPropertyAdvice.class);

boolean mavenPropAdviceExists = false;
for (IPropertyAdvice entry : advices) {
if (entry instanceof MavenPropertiesAdvice) {
mavenPropAdviceExists = true;
entry.getArtifactProperties(null, simpleArtifactDescriptor);
}
}

if (!mavenPropAdviceExists) {
throw new ProvisionException(
"MavenPropertiesAdvice does not exist for artifact: " + simpleArtifactDescriptor);
}

String mavenArtifactClassifier = getRootFileArtifactClassifier(
simpleArtifactDescriptor.getArtifactKey().getId());
simpleArtifactDescriptor.setProperty(TychoConstants.PROP_CLASSIFIER, mavenArtifactClassifier);
//Type and extension are the same for rootfiles ...
simpleArtifactDescriptor.setProperty(TychoConstants.PROP_EXTENSION, TychoConstants.ROOTFILE_EXTENSION);
simpleArtifactDescriptor.setProperty(TychoConstants.PROP_TYPE, TychoConstants.ROOTFILE_EXTENSION);

target = new BufferedOutputStream(new FileOutputStream(outputFile));

this.publishedArtifacts.put(mavenArtifactClassifier,
new P2Artifact(outputFile, Collections.<IInstallableUnit> emptySet(), simpleArtifactDescriptor));

descriptors.add(simpleArtifactDescriptor);
} catch (FileNotFoundException e) {
throw new ProvisionException(e.getMessage(), e);
}

return target;
}

String getRootFileArtifactClassifier(String artifactId) {
List<IPublisherAdvice> adviceList = this.publisherInfo.getAdvice();

Expand All @@ -131,6 +105,35 @@ String getRootFileArtifactClassifier(String artifactId) {
}

public Map<String, IP2Artifact> getPublishedArtifacts() {
return publishedArtifacts;
if (collect == null) {
this.descriptors.removeAll(temp);
collect = artifactsToPublish.entrySet().stream().map(entry -> {
File outputFile = entry.getKey();
IArtifactKey artifactKey = entry.getValue();
IArtifactDescriptor artifactDescriptor = PublisherHelper.createArtifactDescriptor(publisherInfo,
artifactKey, outputFile);
Collection<IPropertyAdvice> advices = publisherInfo.getAdvice(null, false,
artifactDescriptor.getArtifactKey().getId(), artifactDescriptor.getArtifactKey().getVersion(),
IPropertyAdvice.class);

for (IPropertyAdvice advice : advices) {
if (advice instanceof MavenPropertiesAdvice) {
advice.getArtifactProperties(null, artifactDescriptor);
}
}
String mavenArtifactClassifier = getRootFileArtifactClassifier(
artifactDescriptor.getArtifactKey().getId());
if (artifactDescriptor instanceof ArtifactDescriptor impl) {
impl.setProperty(TychoConstants.PROP_CLASSIFIER, mavenArtifactClassifier);
//Type and extension are the same for rootfiles ...
impl.setProperty(PROP_EXTENSION, TychoConstants.ROOTFILE_EXTENSION);
impl.setProperty(TychoConstants.PROP_TYPE, TychoConstants.ROOTFILE_EXTENSION);
}
addDescriptor(artifactDescriptor);
return Map.entry(mavenArtifactClassifier,
new P2Artifact(outputFile, Collections.<IInstallableUnit> emptySet(), artifactDescriptor));
}).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
}
return collect;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public IArtifactSink newAddingArtifactSink(IArtifactKey key, WriteSessionContext
@Override
protected void internalStore(IProgressMonitor monitor) {
try {
internalStoreWithException();
saveToDisk();
} catch (IOException e) {
String message = "Error while writing repository to " + p2DataFile;
// TODO 393004 Use a specific type?
Expand All @@ -222,7 +222,7 @@ protected void internalStore(IProgressMonitor monitor) {

private void storeOrProvisioningException() throws ProvisionException {
try {
internalStoreWithException();
saveToDisk();
} catch (IOException e) {
String message = "Error while writing repository to " + p2DataFile;
int code = ProvisionException.REPOSITORY_FAILED_WRITE;
Expand All @@ -231,7 +231,7 @@ private void storeOrProvisioningException() throws ProvisionException {
}
}

private void internalStoreWithException() throws IOException {
public void saveToDisk() throws IOException {
ArtifactsIO io = new ArtifactsIO();
io.writeXML(flattenedValues().collect(toSet()), p2DataFile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ public void testRepoWithInitEmptyAttachedArtifacts() {
}

private void assertMavenProperties(IArtifactDescriptor descriptor, String root) {
Assert.assertEquals(descriptor.getProperty("maven-groupId"), "artifactGroupId");
Assert.assertEquals(descriptor.getProperty("maven-artifactId"), "artifactId");
Assert.assertEquals(descriptor.getProperty("maven-version"), "artifactVersion");
Assert.assertEquals(descriptor.getProperty("maven-classifier"), root);
Assert.assertEquals(descriptor.getProperty("maven-extension"), "zip");
Assert.assertEquals("artifactGroupId", descriptor.getProperty("maven-groupId"));
Assert.assertEquals("artifactId", descriptor.getProperty("maven-artifactId"));
Assert.assertEquals("artifactVersion", descriptor.getProperty("maven-version"));
Assert.assertEquals(root, descriptor.getProperty("maven-classifier"));
Assert.assertEquals("zip", descriptor.getProperty("maven-extension"));
}

private void assertAttachedArtifact(Map<String, IP2Artifact> attachedArtifacts, int expectedSize,
Expand Down
82 changes: 82 additions & 0 deletions tycho-its/projects/p2Repository.downloadVerifyNoDigestAlgo/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>tycho-its-project.p2Repository.downloadVerifyNoDigestAlgo</groupId>
<artifactId>tycho-its-project.p2Repository.downloadVerifyNoDigestAlgo.root</artifactId>
<version>1.0.0-SNAPSHOT</version>

<packaging>pom</packaging>

<modules>
<module>test.feature</module>
<module>test.product</module>
<module>test.target</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>tycho-compiler-plugin</artifactId>
<version>${tycho-version}</version>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-packaging-plugin</artifactId>
<version>${tycho-version}</version>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<target>
<artifact>
<groupId>tycho-its-project.p2Repository.downloadVerifyNoDigestAlgo</groupId>
<artifactId>tycho-its-project.p2Repository.downloadVerifyNoDigestAlgo.target</artifactId>
<version>1.0.0-SNAPSHOT</version>
</artifact>
</target>
<executionEnvironment>org.eclipse.justj.openjdk.hotspot.jre.full-17</executionEnvironment>
<environments>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86_64</arch>
</environment>
</environments>
<pomDependencies>consider</pomDependencies>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<id>default-p2-metadata-default</id>
<configuration>
<attachP2Metadata>false</attachP2Metadata>
</configuration>
</execution>
<execution>
<id>attach-p2-metadata</id>
<phase>package</phase>
<goals>
<goal>p2-metadata</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin.includes=feature.xml
root=file:extra.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Intentionally empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<feature
id="tycho-its-project.p2Repository.downloadVerifyNoDigestAlgo.feature"
label="Test Feature"
version="1.0.0.qualifier">

<requires>
<import feature="org.eclipse.platform" version="4.27.0" match="compatible"/>
<import feature="org.eclipse.justj.openjdk.hotspot.jre.full" version="17.0.5" match="compatible"/>
<import plugin="org.eclipse.pde.runtime"/>
</requires>

<plugin id="com.github.com-github-javabdd.com.github.javabdd" version="6.0.0" match="compatible"/>
<plugin id="org.apache.commons.commons-text" version="1.10.0" match="compatible"/>

</feature>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>

<parent>
<groupId>tycho-its-project.p2Repository.downloadVerifyNoDigestAlgo</groupId>
<artifactId>tycho-its-project.p2Repository.downloadVerifyNoDigestAlgo.root</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

<artifactId>tycho-its-project.p2Repository.downloadVerifyNoDigestAlgo.feature</artifactId>
<packaging>eclipse-feature</packaging>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<site>
</site>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>

<parent>
<groupId>tycho-its-project.p2Repository.downloadVerifyNoDigestAlgo</groupId>
<artifactId>tycho-its-project.p2Repository.downloadVerifyNoDigestAlgo.root</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

<artifactId>tycho-its-project.p2Repository.downloadVerifyNoDigestAlgo.product</artifactId>
<packaging>eclipse-repository</packaging>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-repository-plugin</artifactId>
<version>${tycho-version}</version>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-director-plugin</artifactId>
<version>${tycho-version}</version>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<?pde version="3.5"?>
<product name="Test product" uid="tycho-its-project.p2Repository.downloadVerifyNoDigestAlgo.product" id="tycho-its-project.p2Repository.downloadVerifyNoDigestAlgo.product" application="org.eclipse.ui.ide.workbench" version="1.0.0.qualifier" useFeatures="true" includeLaunchers="true" autoIncludeRequirements="true">

<features>
<feature id="tycho-its-project.p2Repository.downloadVerifyNoDigestAlgo.feature" version="1.0.0.qualifier"/>
</features>

<configurations>
<plugin id="org.apache.felix.scr" autoStart="true" startLevel="2" />
<plugin id="org.eclipse.core.runtime" autoStart="true" startLevel="0" />
<plugin id="org.eclipse.equinox.common" autoStart="true" startLevel="2" />
<plugin id="org.eclipse.equinox.event" autoStart="true" startLevel="2" />
<plugin id="org.eclipse.equinox.simpleconfigurator" autoStart="true" startLevel="1" />
</configurations>

</product>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>

<parent>
<groupId>tycho-its-project.p2Repository.downloadVerifyNoDigestAlgo</groupId>
<artifactId>tycho-its-project.p2Repository.downloadVerifyNoDigestAlgo.root</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

<artifactId>tycho-its-project.p2Repository.downloadVerifyNoDigestAlgo.target</artifactId>
<packaging>eclipse-target-definition</packaging>
</project>
Loading
Loading