-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add CranPackageURLHandlerImpl and test * test/java/com/devonfw/tools/solicitor/common/packageurl/impl/CranPackageURLHandlerTests.java * adapt * improve java doc * adaopt asciidoc * adapt application.properties * return URL of source archive also for the package url --------- Co-authored-by: ohecker <[email protected]>
- Loading branch information
1 parent
ba468a4
commit 4873da9
Showing
5 changed files
with
170 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...in/java/com/devonfw/tools/solicitor/common/packageurl/impl/CranPackageURLHandlerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.devonfw.tools.solicitor.common.packageurl.impl; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.github.packageurl.PackageURL; | ||
|
||
/** | ||
* Specific handling of packageURLs of "cran" type. | ||
*/ | ||
@Component | ||
public class CranPackageURLHandlerImpl extends AbstractSingleKindPackageURLHandler { | ||
private String repoBaseUrl; | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param repoBaseUrl the repository base url | ||
*/ | ||
@Autowired | ||
public CranPackageURLHandlerImpl(@Value("${packageurls.cran.repobaseurl}") String repoBaseUrl) { | ||
|
||
super(); | ||
// Sicherstellen, dass repoBaseUrl mit einem "/" endet | ||
if (!repoBaseUrl.endsWith("/")) { | ||
repoBaseUrl += "/"; | ||
} | ||
this.repoBaseUrl = repoBaseUrl; | ||
} | ||
|
||
/** | ||
* Determines if this handler can handle the given package URL. | ||
* | ||
* @param packageURL the package URL to check. | ||
* @return true if the handler can handle the URL, false otherwise. | ||
*/ | ||
@Override | ||
public boolean canHandle(PackageURL packageURL) { | ||
|
||
return "cran".equalsIgnoreCase(packageURL.getType()); | ||
} | ||
|
||
/** | ||
* Returns the source download URL for CRAN packages. | ||
* | ||
* @param purl the package URL. | ||
* @return the source download URL. | ||
*/ | ||
@Override | ||
protected String doSourceDownloadUrlFor(PackageURL purl) { | ||
|
||
StringBuilder sb = new StringBuilder(this.repoBaseUrl); | ||
sb.append("src/contrib/"); | ||
sb.append(purl.getName()); | ||
sb.append("_").append(purl.getVersion()); | ||
sb.append(".tar.gz"); | ||
return sb.toString(); | ||
} | ||
|
||
/** | ||
* Returns the package download URL for CRAN packages. | ||
* | ||
* @param purl the package URL. | ||
* @return the package download URL. This will return the archive of sources (same as | ||
* {@link #doSourceDownloadUrlFor(PackageURL)}. There are pre-compiled binaries available on the server, but | ||
* those are OS and version specific, so no universal binary. | ||
*/ | ||
@Override | ||
protected String doPackageDownloadUrlFor(PackageURL purl) { | ||
|
||
StringBuilder sb = new StringBuilder(this.repoBaseUrl); | ||
sb.append("src/contrib/"); | ||
sb.append(purl.getName()); | ||
sb.append("_").append(purl.getVersion()); | ||
sb.append(".tar.gz"); | ||
return sb.toString(); | ||
} | ||
|
||
/** | ||
* Returns the suffix for source archive files for CRAN packages. | ||
* | ||
* @param purl the package URL. | ||
* @return the suffix for the source archive (".tar.gz"). | ||
*/ | ||
@Override | ||
protected String doSourceArchiveSuffixFor(PackageURL purl) { | ||
|
||
return "tar.gz"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...t/java/com/devonfw/tools/solicitor/common/packageurl/impl/CranPackageURLHandlerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.devonfw.tools.solicitor.common.packageurl.impl; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Tests for {@link CranPackageURLHandlerImpl} | ||
* | ||
*/ | ||
class CranPackageURLHandlerTests { | ||
|
||
@Test | ||
void testSourceDownloadUrlFor() { | ||
|
||
CranPackageURLHandlerImpl handler = new CranPackageURLHandlerImpl("http://test/"); | ||
assertEquals("http://test/src/contrib/someprod_4.5.35.tar.gz", | ||
handler.sourceDownloadUrlFor("pkg:cran/[email protected]")); | ||
|
||
} | ||
|
||
@Test | ||
void testPackageDownloadUrlFor() { | ||
|
||
CranPackageURLHandlerImpl handler = new CranPackageURLHandlerImpl("http://test/"); | ||
assertEquals("http://test/src/contrib/someprod_4.5.35.tar.gz", | ||
handler.packageDownloadUrlFor("pkg:cran/[email protected]")); | ||
|
||
} | ||
|
||
@Test | ||
void testCanHandle() { | ||
|
||
CranPackageURLHandlerImpl handler = new CranPackageURLHandlerImpl("http://test/"); | ||
assertTrue(handler.canHandle(handler.parse("pkg:cran/a@1"))); | ||
assertFalse(handler.canHandle(handler.parse("pkg:crana/a@1"))); | ||
} | ||
|
||
@Test | ||
void testSourceArchiveSuffixFor() { | ||
|
||
CranPackageURLHandlerImpl handler = new CranPackageURLHandlerImpl("http://test/"); | ||
assertEquals("tar.gz", handler.sourceArchiveSuffixFor("pkg:cran/[email protected]")); | ||
} | ||
|
||
@Test | ||
void testPathFor() { | ||
|
||
CranPackageURLHandlerImpl handler = new CranPackageURLHandlerImpl("http://test/"); | ||
assertEquals("pkg/cran/someprod/4.5.35", handler.pathFor("pkg:cran/[email protected]")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters