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

Add mojo as a replacement for the p2.emove-iu and task #3841

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
30 changes: 30 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,36 @@ You can enable this for example like this:
</plugin>
```

### New `remove-iu` mojo

This is a replacement for the [p2.remove.iu ant task](https://help.eclipse.org/latest/topic/org.eclipse.platform.doc.isv/guide/p2_repositorytasks.htm), example:

```xml
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-repository-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<id>remove-iu</id>
<goals>
<goal>remove-iu</goal>
</goals>
<phase>package</phase>
<configuration>
<iu>
<remove>
<query>property[@name='org.eclipse.equinox.p2.name' @value='Uncategorized']</query>
</remove>
<remove>
<id>eclipse-junit-tests</id>
</remove>
</iu>
</configuration>
</execution>
</executions>
</plugin>
```

### New `repo-to-runnable` mojo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.tycho.p2maven.repository;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
Expand All @@ -25,6 +26,8 @@
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepositoryFactory;
import org.eclipse.equinox.internal.p2.metadata.repository.SimpleMetadataRepositoryFactory;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
Expand Down Expand Up @@ -76,6 +79,21 @@ public IArtifactRepository getArtifactRepository(Repository repository)
return getArtifactRepository(new URI(repository.getUrl()), repository.getId());
}

/**
* Loads the {@link IArtifactRepository} from the given {@link File}, this
* method does NOT check the type of the repository!
*
* @param repository
* @param flags
* @return the {@link IArtifactRepository} for the given {@link Repository}
* @throws ProvisionException if loading the repository failed
*/
public IArtifactRepository getArtifactRepository(File repository, int flags) throws ProvisionException {
SimpleArtifactRepositoryFactory factory = new SimpleArtifactRepositoryFactory();
factory.setAgent(agent);
return factory.load(repository.toURI(), flags, null);
}

/**
* Loads the {@link IArtifactRepository} from the given {@link Repository}, this
* method does NOT check the type of the repository!
Expand Down Expand Up @@ -116,6 +134,21 @@ public IMetadataRepository getMetadataRepository(Repository repository)
return getMetadataRepositor(new URI(repository.getUrl()), repository.getId());
}

/**
* Loads the {@link IMetadataRepository} from the given {@link File}, this
* method does NOT check the type of the repository!
*
* @param repository
* @param flags the flags to use
* @return the {@link IMetadataRepository} for the given {@link Repository}
* @throws ProvisionException if loading the repository failed
*/
public IMetadataRepository getMetadataRepository(File repository, int flags) throws ProvisionException {
SimpleMetadataRepositoryFactory factory = new SimpleMetadataRepositoryFactory();
factory.setAgent(agent);
return factory.load(repository.toURI(), flags, null);
}

public IQueryable<IInstallableUnit> getCompositeMetadataRepository(Collection<Repository> repositories)
throws ProvisionException, URISyntaxException {
if (repositories.size() == 1) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Category
# Repositories

Repositories (also knows as P2 Updatesites) contain artifacts and metadata to install content into eclipse or use them in a Tycho build.

## Create Repositories using category.xml

A category.xml file can be used to define which content is placed into a p2 repository.
It can also specify how to display the content in the p2 installation dialog.
Expand Down Expand Up @@ -68,3 +72,15 @@ The following is an example, demonstrating a complex category definition.
```

You can read more about P2 Query Syntax [here](https://wiki.eclipse.org/Equinox/p2/Query_Language_for_p2).

## Managing Repositories

Tycho offers some tools to manage existing repositories as a replacement for the ant-tasks described [here](https://help.eclipse.org/latest/topic/org.eclipse.platform.doc.isv/guide/p2_repositorytasks.htm)

### repo2runnable

See [tycho-p2-repository:repo-to-runnable](tycho-p2-repository-plugin/repo-to-runnable-mojo.html)

### remove.iu

See [tycho-p2-repository:remove-iu](tycho-p2-repository-plugin/remove-iu-mojo.html)
4 changes: 4 additions & 0 deletions src/site/site.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
</item>
<item name="Tycho CI Friendly Versions" href="TychoCiFriendly.html" />
<item name="Creating update sites using category.xml" href="Category.html">
</item>
<item name="Repositories" href="Repositories.html">
<item name="Tycho P2 Repository Plugin" href="tycho-p2-repository-plugin/plugin-info.html" />
<item name="Tycho P2 Repository Plugin" href="tycho-p2-repository-plugin/plugin-info.html" />

</item>
<item name="Properties">
<item name="Build Properties" href="BuildProperties.html" />
Expand Down
5 changes: 5 additions & 0 deletions tycho-its/projects/p2Repository.removeUI/category.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- includes three bundles in different ways; note: the bundles do not require each other -->
<site>
<bundle id="org.eclipse.osgi" version="3.5.2.R35x_v20100126"/>
</site>
61 changes: 61 additions & 0 deletions tycho-its/projects/p2Repository.removeUI/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?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 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>tycho-its-project.p2Repository</groupId>
<artifactId>testrepo</artifactId>
<version>1.0.0</version>

<properties>
<tycho-version>5.0.0-SNAPSHOT</tycho-version>
</properties>
<packaging>eclipse-repository</packaging>

<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-p2-repository-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<compress>false</compress>
</configuration>
<executions>
<execution>
<goals>
<goal>remove-iu</goal>
</goals>
<phase>package</phase>
<configuration>
<iu>
<remove>
<query>property[@name='org.eclipse.equinox.p2.name' @value='Uncategorized']</query>
</remove>
<remove>
<id>a.jre.javase</id>
</remove>
</iu>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>test-data-repo</id>
<layout>p2</layout>
<url>${test-data-repo}</url>
</repository>
</repositories>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import de.pdark.decentxml.XMLIOSource;
import de.pdark.decentxml.XMLParser;

public class P2ExtrasPlugin extends AbstractTychoIntegrationTest {
public class P2ExtrasPluginTest extends AbstractTychoIntegrationTest {

@Test
public void testBaseline() throws Exception {
Expand Down Expand Up @@ -171,7 +171,7 @@ private static boolean hasChildWithZippedAttribute(Element element) {
if ("zipped".equals(element.getAttributeValue("key"))) {
return true;
}
return element.getChildren().stream().anyMatch(P2ExtrasPlugin::hasChildWithZippedAttribute);
return element.getChildren().stream().anyMatch(P2ExtrasPluginTest::hasChildWithZippedAttribute);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*******************************************************************************
* Copyright (c) 2024 Christoph Läubrich 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
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christoph Läubrich - initial API and implementation
*******************************************************************************/
package org.eclipse.tycho.test;

import static org.junit.Assert.assertNotEquals;

import java.io.File;
import java.util.List;

import org.apache.maven.it.Verifier;
import org.eclipse.tycho.test.util.P2RepositoryTool;
import org.eclipse.tycho.test.util.P2RepositoryTool.IU;
import org.eclipse.tycho.test.util.P2RepositoryTool.IdAndVersion;
import org.eclipse.tycho.test.util.ResourceUtil;
import org.junit.Test;

public class P2RepositoryPluginTest extends AbstractTychoIntegrationTest {

@Test
public void testP2RemoveUI() throws Exception {
Verifier verifier = getVerifier("/p2Repository.removeUI");
verifier.addCliOption("-Dtest-data-repo=" + ResourceUtil.P2Repositories.ECLIPSE_352);
verifier.executeGoals(List.of("clean", "package"));
verifier.verifyErrorFreeLog();
P2RepositoryTool p2Repo = P2RepositoryTool.forEclipseRepositoryModule(new File(verifier.getBasedir()));
List<IdAndVersion> allUnits = p2Repo.getAllUnits();
for (IdAndVersion idAndVersion : allUnits) {
IU iu = p2Repo.getIU(idAndVersion.id(), idAndVersion.version());
for (String prop : iu.getProperties()) {
assertNotEquals("org.eclipse.equinox.p2.name=Uncategorized", prop);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@
<exportedPackage>org.eclipse.equinox.p2.publisher</exportedPackage>
<exportedPackage>org.eclipse.equinox.p2.publisher.eclipse</exportedPackage>
<exportedPackage>org.eclipse.equinox.p2.query</exportedPackage>
<exportedPackage>org.eclipse.equinox.p2.repository</exportedPackage>
<exportedPackage>org.eclipse.equinox.p2.repository.artifact</exportedPackage>
<exportedPackage>org.eclipse.equinox.p2.repository.metadata</exportedPackage>
<exportedPackage>org.eclipse.equinox.internal.p2.metadata</exportedPackage>
<exportedPackage>org.eclipse.equinox.internal.p2.publisher.eclipse</exportedPackage>
<exportedPackage>org.eclipse.core.runtime.IProgressMonitor</exportedPackage>
<exportedPackage>org.eclipse.core.runtime.NullProgressMonitor</exportedPackage>
<exportedPackage>org.eclipse.core.runtime.SubMonitor</exportedPackage>
<!-- <exportedPackage>org.eclipse.core.runtime</exportedPackage>
<exportedPackage>org.eclipse.core.resources</exportedPackage> -->
<!-- other -->
Expand Down
Loading
Loading