From 85a2495116da48f4a4328a9066a7147c9e363b70 Mon Sep 17 00:00:00 2001 From: Mat Booth Date: Wed, 11 Nov 2020 10:04:50 +0000 Subject: [PATCH 8/9] Bug 561832 - Upgrade to [takari/polyglot-maven] Release 0.4.5 --- tycho-extras/tycho-pomless/pom.xml | 2 +- .../tycho/pomless/AbstractTychoMapping.java | 3 ++ .../pomless/AbstractXMLTychoMapping.java | 5 +-- .../tycho/pomless/TychoAggregatorMapping.java | 6 +-- .../tycho/pomless/TychoBundleMapping.java | 40 ++++++++----------- .../tycho/pomless/TychoMappingTest.java | 5 ++- .../tycho/pomless/TychoModelReaderTest.java | 27 +++++++------ 7 files changed, 39 insertions(+), 49 deletions(-) diff --git a/tycho-extras/tycho-pomless/pom.xml b/tycho-extras/tycho-pomless/pom.xml index b1979ff..2ab14a8 100644 --- a/tycho-extras/tycho-pomless/pom.xml +++ b/tycho-extras/tycho-pomless/pom.xml @@ -47,7 +47,7 @@ io.takari.polyglot polyglot-common - 0.4.4 + 0.4.5 org.eclipse.sisu diff --git a/tycho-extras/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/AbstractTychoMapping.java b/tycho-extras/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/AbstractTychoMapping.java index d6a9977..b80c22b 100644 --- a/tycho-extras/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/AbstractTychoMapping.java +++ b/tycho-extras/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/AbstractTychoMapping.java @@ -114,6 +114,9 @@ public abstract class AbstractTychoMapping implements Mapping, ModelReader { public Model read(File input, Map options) throws IOException, ModelParseException { File artifactFile = getRealArtifactFile(input); if (artifactFile.exists()) { + if (artifactFile.isDirectory()) { + return read(new StringReader(""), input, options); + } try (InputStreamReader stream = new InputStreamReader(new FileInputStream(artifactFile), getPrimaryArtifactCharset())) { return read(stream, input, options); diff --git a/tycho-extras/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/AbstractXMLTychoMapping.java b/tycho-extras/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/AbstractXMLTychoMapping.java index 955b78a..05505d1 100644 --- a/tycho-extras/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/AbstractXMLTychoMapping.java +++ b/tycho-extras/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/AbstractXMLTychoMapping.java @@ -85,9 +85,6 @@ public abstract class AbstractXMLTychoMapping extends AbstractTychoMapping { @Override public float getPriority() { - //FIXME due to - // https://github.com/takari/polyglot-maven/issues/209 - // we must use inverse logic and return lower values for higher priorities - return -1; + return 1; } } diff --git a/tycho-extras/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/TychoAggregatorMapping.java b/tycho-extras/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/TychoAggregatorMapping.java index 8043dfe..39183d7 100644 --- a/tycho-extras/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/TychoAggregatorMapping.java +++ b/tycho-extras/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/TychoAggregatorMapping.java @@ -110,11 +110,7 @@ public class TychoAggregatorMapping extends AbstractTychoMapping { @Override public float getPriority() { - //use a lower priority here so other modules are asked first - //FIXME due to - // https://github.com/takari/polyglot-maven/issues/209 - // we must use inverse logic and return lower values for higher priorities - return 10f; + return -10f; } } diff --git a/tycho-extras/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/TychoBundleMapping.java b/tycho-extras/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/TychoBundleMapping.java index d450750..0d7baeb 100644 --- a/tycho-extras/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/TychoBundleMapping.java +++ b/tycho-extras/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/TychoBundleMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019 Lablicate GmbH and others. + * Copyright (c) 2019, 2020 Lablicate GmbH and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -29,30 +29,30 @@ import org.sonatype.maven.polyglot.mapping.Mapping; @Component(role = Mapping.class, hint = TychoBundleMapping.PACKAGING) public class TychoBundleMapping extends AbstractTychoMapping { - private static final String BUNDLE_SYMBOLIC_NAME = "Bundle-SymbolicName"; - + public static final String META_INF_DIRECTORY = "META-INF"; + public static final String MANIFEST_MF = "MANIFEST.MF"; public static final String PACKAGING = "eclipse-plugin"; + + private static final String BUNDLE_SYMBOLIC_NAME = "Bundle-SymbolicName"; private static final String PACKAGING_TEST = "eclipse-test-plugin"; - private static final String MANIFEST_MF = "META-INF/MANIFEST.MF"; - public static final String MANIFEST_MF_MARKER = ".META-INF_MANIFEST.MF"; @Override protected boolean isValidLocation(String location) { - return location.endsWith(MANIFEST_MF_MARKER); + File polyglotArtifactFile = new File(location); + if (polyglotArtifactFile.isDirectory() && polyglotArtifactFile.getName().equals(META_INF_DIRECTORY)) { + return new File(polyglotArtifactFile, MANIFEST_MF).exists(); + } + return false; } @Override protected File getPrimaryArtifact(File dir) { - File manifestFile = new File(dir, MANIFEST_MF); - if (manifestFile.isFile()) { - File markerFile = new File(dir, MANIFEST_MF_MARKER); - try { - markerFile.createNewFile(); - } catch (IOException e) { - throw new RuntimeException("can't create markerfile", e); + File metaInfDirectory = new File(dir, META_INF_DIRECTORY); + if (metaInfDirectory.isDirectory()) { + File manifestFile = new File(metaInfDirectory, MANIFEST_MF); + if (manifestFile.isFile()) { + return metaInfDirectory; } - markerFile.deleteOnExit(); - return markerFile; } return null; } @@ -66,7 +66,7 @@ public class TychoBundleMapping extends AbstractTychoMapping { protected void initModel(Model model, Reader artifactReader, File artifactFile) throws ModelParseException, IOException { File bundleRoot = artifactFile.getParentFile(); - File manifestFile = new File(bundleRoot, MANIFEST_MF); + File manifestFile = new File(artifactFile, MANIFEST_MF); Attributes manifestHeaders = readManifestHeaders(manifestFile); String bundleSymbolicName = getBundleSymbolicName(manifestHeaders, manifestFile); // groupId is inherited from parent pom @@ -94,14 +94,6 @@ public class TychoBundleMapping extends AbstractTychoMapping { } } - @Override - protected File getRealArtifactFile(File polyglotArtifactFile) { - if (polyglotArtifactFile.getName().equals(MANIFEST_MF_MARKER)) { - return new File(polyglotArtifactFile.getParentFile(), MANIFEST_MF); - } - return super.getRealArtifactFile(polyglotArtifactFile); - } - private Attributes readManifestHeaders(File manifestFile) throws IOException { Manifest manifest = new Manifest(); try (FileInputStream stream = new FileInputStream(manifestFile)) { diff --git a/tycho-extras/tycho-pomless/src/test/java/org/eclipse/tycho/pomless/TychoMappingTest.java b/tycho-extras/tycho-pomless/src/test/java/org/eclipse/tycho/pomless/TychoMappingTest.java index 910150c..641cec3 100644 --- a/tycho-extras/tycho-pomless/src/test/java/org/eclipse/tycho/pomless/TychoMappingTest.java +++ b/tycho-extras/tycho-pomless/src/test/java/org/eclipse/tycho/pomless/TychoMappingTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 SAP SE and others. + * 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 @@ -7,6 +7,7 @@ * * Contributors: * SAP SE - initial API and implementation + * Christoph Läubrich - adjust to changed API *******************************************************************************/ package org.eclipse.tycho.pomless; @@ -27,7 +28,7 @@ public class TychoMappingTest extends PlexusTestCase { public void testLocateBuildProperties() throws Exception { File pom = polyglotModelManager.locatePom(new File(getMappingTestDir(), "simple")); assertNotNull(pom); - assertEquals(TychoBundleMapping.MANIFEST_MF_MARKER, pom.getName()); + assertEquals(TychoBundleMapping.META_INF_DIRECTORY, pom.getName()); } public void testPriority() throws Exception { diff --git a/tycho-extras/tycho-pomless/src/test/java/org/eclipse/tycho/pomless/TychoModelReaderTest.java b/tycho-extras/tycho-pomless/src/test/java/org/eclipse/tycho/pomless/TychoModelReaderTest.java index 134987f..67ba7c2 100644 --- a/tycho-extras/tycho-pomless/src/test/java/org/eclipse/tycho/pomless/TychoModelReaderTest.java +++ b/tycho-extras/tycho-pomless/src/test/java/org/eclipse/tycho/pomless/TychoModelReaderTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2019 SAP SE and others. + * 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 @@ -7,6 +7,7 @@ * * Contributors: * SAP SE - initial API and implementation + * Christoph Läubrich - adjust to API *******************************************************************************/ package org.eclipse.tycho.pomless; @@ -36,7 +37,7 @@ public class TychoModelReaderTest extends PlexusTestCase { @Test public void testReadBundle() throws Exception { - File buildProperties = new File(getPolyglotTestDir(), "bundle1/" + TychoBundleMapping.MANIFEST_MF_MARKER); + File buildProperties = new File(getPolyglotTestDir(), "bundle1/" + TychoBundleMapping.META_INF_DIRECTORY); Model model = getTychoModelReader(TychoBundleMapping.PACKAGING).read(buildProperties, createReaderOptions(buildProperties)); assertEquals("4.0.0", model.getModelVersion()); @@ -45,12 +46,12 @@ public class TychoModelReaderTest extends PlexusTestCase { assertEquals("0.1.0-SNAPSHOT", model.getVersion()); assertEquals("eclipse-plugin", model.getPackaging()); assertParent(model.getParent()); - assertLocation("bundle1/META-INF/MANIFEST.MF", model.getLocation("")); + assertLocation("bundle1/META-INF", model.getLocation("")); } @Test public void testReadBundle2() throws Exception { - File buildProperties = new File(getPolyglotTestDir(), "bundle2/" + TychoBundleMapping.MANIFEST_MF_MARKER); + File buildProperties = new File(getPolyglotTestDir(), "bundle2/" + TychoBundleMapping.META_INF_DIRECTORY); Model model = getTychoModelReader(TychoBundleMapping.PACKAGING).read(buildProperties, createReaderOptions(buildProperties)); assertEquals("4.0.0", model.getModelVersion()); @@ -59,12 +60,12 @@ public class TychoModelReaderTest extends PlexusTestCase { assertEquals("0.1.0-SNAPSHOT", model.getVersion()); assertEquals("eclipse-plugin", model.getPackaging()); assertParent(model.getParent()); - assertLocation("bundle2/META-INF/MANIFEST.MF", model.getLocation("")); + assertLocation("bundle2/META-INF", model.getLocation("")); } @Test public void testReadBundle3() throws Exception { - File buildProperties = new File(getPolyglotTestDir(), "bundle3/" + TychoBundleMapping.MANIFEST_MF_MARKER); + File buildProperties = new File(getPolyglotTestDir(), "bundle3/" + TychoBundleMapping.META_INF_DIRECTORY); Model model = getTychoModelReader(TychoBundleMapping.PACKAGING).read(buildProperties, createReaderOptions(buildProperties)); assertEquals("4.0.0", model.getModelVersion()); @@ -73,19 +74,19 @@ public class TychoModelReaderTest extends PlexusTestCase { assertEquals("0.1.0-SNAPSHOT", model.getVersion()); assertEquals("eclipse-plugin", model.getPackaging()); assertParent(model.getParent()); - assertLocation("bundle3/META-INF/MANIFEST.MF", model.getLocation("")); + assertLocation("bundle3/META-INF", model.getLocation("")); } @Test public void testReadTestBundle() throws Exception { - File buildProperties = new File(getPolyglotTestDir(), "bundle1.tests/" + TychoBundleMapping.MANIFEST_MF_MARKER); + File buildProperties = new File(getPolyglotTestDir(), "bundle1.tests/" + TychoBundleMapping.META_INF_DIRECTORY); Model model = getTychoModelReader(TychoBundleMapping.PACKAGING).read(buildProperties, createReaderOptions(buildProperties)); assertEquals("pomless.bundle.tests", model.getArtifactId()); assertEquals("1.0.1", model.getVersion()); assertEquals("eclipse-test-plugin", model.getPackaging()); assertParent(model.getParent()); - assertLocation("bundle1.tests/META-INF/MANIFEST.MF", model.getLocation("")); + assertLocation("bundle1.tests/META-INF", model.getLocation("")); } @Test @@ -158,7 +159,7 @@ public class TychoModelReaderTest extends PlexusTestCase { @Test public void testBundleWithoutSymbolicName() throws Exception { File buildProperties = new File(getTestResourcesDir(), - "modelreader/plugins/missingBsn/" + TychoBundleMapping.MANIFEST_MF_MARKER); + "modelreader/plugins/missingBsn/" + TychoBundleMapping.META_INF_DIRECTORY); try { getTychoModelReader(TychoBundleMapping.PACKAGING).read(buildProperties, createReaderOptions(buildProperties)); @@ -171,7 +172,7 @@ public class TychoModelReaderTest extends PlexusTestCase { @Test public void testBundleWithoutVersion() throws Exception { File buildProperties = new File(getTestResourcesDir(), - "modelreader/plugins/missingVersion/" + TychoBundleMapping.MANIFEST_MF_MARKER); + "modelreader/plugins/missingVersion/" + TychoBundleMapping.META_INF_DIRECTORY); try { getTychoModelReader(TychoBundleMapping.PACKAGING).read(buildProperties, createReaderOptions(buildProperties)); @@ -184,7 +185,7 @@ public class TychoModelReaderTest extends PlexusTestCase { @Test public void testNoParent() throws Exception { File buildProperties = new File(getTestResourcesDir(), - "modelreader/noParent/bundle/" + TychoBundleMapping.MANIFEST_MF_MARKER); + "modelreader/noParent/bundle/" + TychoBundleMapping.META_INF_DIRECTORY); FileNotFoundException e = assertThrows(FileNotFoundException.class, () -> getTychoModelReader(TychoBundleMapping.PACKAGING).read(buildProperties, createReaderOptions(buildProperties))); @@ -194,7 +195,7 @@ public class TychoModelReaderTest extends PlexusTestCase { @Test public void testFindParent() throws Exception { File location = new File(getTestResourcesDir(), - "modelreader/grandparentInheritance/bundle/" + TychoBundleMapping.MANIFEST_MF_MARKER); + "modelreader/grandparentInheritance/bundle/" + TychoBundleMapping.META_INF_DIRECTORY); Model model = getTychoModelReader(TychoBundleMapping.PACKAGING).read(location, createReaderOptions(location)); assertNotNull(model); Parent parentReference = model.getParent(); -- 2.28.0