Skip to content

Commit

Permalink
Add IT for a P2 repository hosting server with a redirection loop
Browse files Browse the repository at this point in the history
# Co-authored-by should list all the other authors of this commit
Co-authored-by: NAME <[email protected]>

# Reviewed-by should list all the reviewers of this commit (NOT the PR!)
Reviewed-by: NAME <[email protected]>
  • Loading branch information
thahnen committed Nov 27, 2024
1 parent 9fa7feb commit d93ba67
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tycho-its/projects/P2RedirectLoop/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<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.P2RedirectionLoop</groupId>
<artifactId>aggregator</artifactId>
<version>1.0.0</version>
<packaging>eclipse-plugin</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<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>
<resolver>p2</resolver>
<executionEnvironment>JavaSE-11</executionEnvironment>
<target>
<file>targetplatform.target</file>
</target>
<environments>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86_64</arch>
</environment>
</environments>
</configuration>
</plugin>
</plugins>
</build>
</project>
10 changes: 10 additions & 0 deletions tycho-its/projects/P2RedirectLoop/targetplatform.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde?>
<target name="P2RedirectLoop" sequenceNumber="1">
<locations>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="slicer" includeSource="true" type="InstallableUnit">
<repository id="loop" location="url"/>
<unit id="loop.feature.group" version="0.0.0"/>
</location>
</locations>
</target>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*******************************************************************************
* Copyright (c) 2024 Tobias Hahnen 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:
* Tobias Hahnen - initial API and implementation
*******************************************************************************/
package org.eclipse.tycho.test.P2RedirectLoop;

import java.io.File;
import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.maven.it.Verifier;
import org.eclipse.tycho.p2maven.transport.RedirectionLoopException;
import org.eclipse.tycho.test.AbstractTychoIntegrationTest;
import org.eclipse.tycho.test.util.HttpServer;
import org.eclipse.tycho.test.util.TargetDefinitionUtil;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.xml.sax.SAXException;

public class P2RedirectLoopTest extends AbstractTychoIntegrationTest {
private HttpServer server;
@Rule
public final TemporaryFolder temporaryFolder = new TemporaryFolder();
private Verifier verifier;

@Before
public void startServer() throws Exception {
server = HttpServer.startServer();
server.addServer("loop", temporaryFolder.getRoot());
verifier = getVerifier("P2RedirectLoop", false);
}

@After
public void stopServer() throws Exception {
if (server != null) {
server.stop();
}
}

@Test
public void test_redirection_loop_warning() throws Exception {
var redirectedUrl = server.addRedirect("loop", originalPath -> originalPath);
configureRepositoryInTargetDefinition(redirectedUrl);
Assert.assertThrows(RedirectionLoopException.class, () -> verifier.executeGoal("package"));
}

private void configureRepositoryInTargetDefinition(String url)
throws IOException, ParserConfigurationException, SAXException {
File platformFile = new File(verifier.getBasedir(), "targetplatform.target");
TargetDefinitionUtil.setRepositoryURLs(platformFile, "loop", url);
}
}

0 comments on commit d93ba67

Please sign in to comment.