diff --git a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/tools/P2RepositoryDataManipulator.java b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/tools/P2RepositoryDataManipulator.java index 2a1dbd5145..68d6c7793f 100644 --- a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/tools/P2RepositoryDataManipulator.java +++ b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/tools/P2RepositoryDataManipulator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2025, 2025 Hannes Wellmann and others. + * Copyright (c) 2025, 2026 Hannes Wellmann and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -133,7 +133,7 @@ public void modifyRepositoryMetadata(ModifiedRepositoryDescriptor repository, St modifyOutputRepository(manager.getMetadataRepository(location.getURL(), location.getId()), outputLocation, manager::mirrorMetadataRepository, r -> r.executeBatch(m -> modification.accept(r), null)); } - xzCompress(repository, outputLocation); + xzCompress(repository); } @FunctionalInterface @@ -155,8 +155,9 @@ private > void modifyOutputRepository(R repository, } } - private void xzCompress(ModifiedRepositoryDescriptor repository, Path outputLocation) throws IOException { + private void xzCompress(ModifiedRepositoryDescriptor repository) throws IOException { if (repository.xzCompress()) { + Path outputLocation = resolveOutputLocation(repository); XZCompressor xzCompressor = new XZCompressor(); xzCompressor.setPreserveOriginalFile(repository.keepNonXzIndexFiles()); xzCompressor.setRepoFolder(outputLocation.toAbsolutePath().toString()); @@ -210,7 +211,7 @@ public void modifyCompositeRepository(ModifiedRepositoryDescriptor repository, S }, modification, CompositeMetadataRepository.PI_REPOSITORY_TYPE, CompositeMetadataRepositoryFactory.CONTENT_FILENAME); } - createP2Index(repository.outputLocation(), repository.isMetadata(), repository.isArtifact()); + createP2Index(resolveOutputLocation(repository), repository.isMetadata(), repository.isArtifact()); } private , R extends ICompositeRepository> void modifyOutputCompositeRepository( @@ -234,15 +235,7 @@ private , R extends ICompositeRepository> throw e; } } - Path outputLocation = descriptor.outputLocation(); - if (outputLocation == null) { - try { - outputLocation = Path.of(repository.getURL()); - } catch (Exception e) { - throw new IllegalStateException( - "Repository is not modifable and no output location is defined: " + repository.getURL(), e); - } - } + Path outputLocation = resolveOutputLocation(descriptor); modification.accept(state); @@ -254,6 +247,20 @@ private , R extends ICompositeRepository> } } + private static Path resolveOutputLocation(ModifiedRepositoryDescriptor descriptor) { + Path outputLocation = descriptor.outputLocation(); + if (outputLocation == null) { // In-place edit + MavenRepositoryLocation repository = descriptor.repository(); + try { + outputLocation = Path.of(repository.getURL()); + } catch (Exception e) { + throw new IllegalStateException( + "Repository is not modifable and no output location is defined: " + repository.getURL(), e); + } + } + return outputLocation; + } + private static OutputStream createCompositeFileOutputStream(Path directory, String filename, boolean compress) throws IOException { Path file = directory.resolve(filename + CompositeArtifactRepository.XML_EXTENSION); diff --git a/tycho-its/projects/issue6251/pom.xml b/tycho-its/projects/issue6251/pom.xml new file mode 100644 index 0000000000..ebcec94cf9 --- /dev/null +++ b/tycho-its/projects/issue6251/pom.xml @@ -0,0 +1,50 @@ + + + + 4.0.0 + + tycho-its-project + issue6251 + 1.0.0-SNAPSHOT + pom + + + + + org.eclipse.tycho + tycho-p2-repository-plugin + ${tycho-version} + + + modify-in-place + initialize + + modify-composite-repository + + + + t + ${project.baseUri}repo/ + + metadata + + ../child + + false + + + + + + + diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/issue6251/Issue6251Test.java b/tycho-its/src/test/java/org/eclipse/tycho/test/issue6251/Issue6251Test.java new file mode 100644 index 0000000000..68a6a6aff3 --- /dev/null +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/issue6251/Issue6251Test.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2026 Contributors to the Eclipse Foundation + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package org.eclipse.tycho.test.issue6251; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + +import org.apache.maven.it.Verifier; +import org.eclipse.tycho.test.AbstractTychoIntegrationTest; +import org.junit.jupiter.api.Test; + +public class Issue6251Test extends AbstractTychoIntegrationTest { + + @Test + public void modifyCompositeRepositoryInPlaceWritesP2Index() throws Exception { + Verifier verifier = getVerifier("issue6251"); + + verifier.executeGoals(List.of("initialize")); + verifier.verifyErrorFreeLog(); + + Path p2Index = Path.of(verifier.getBasedir(), "repo", "p2.index"); + assertTrue(Files.exists(p2Index), "p2.index was not written to the in-place repository"); + } +}