org.codehaus.plexus.util.Os Java Examples
The following examples show how to use
org.codehaus.plexus.util.Os.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InitMojoTest.java From helm-maven-plugin with MIT License | 6 votes |
@DisplayName("Init helm with a automatically detected URL") @Test public void autoDownloadHelm(InitMojo mojo) throws Exception { // prepare execution doNothing().when(mojo).callCli(contains("helm "), anyString(), anyBoolean()); // getHelmExecuteablePath is system-depending and has to be mocked for that reason // as SystemUtils.IS_OS_WINDOWS will always return false on a *NIX system doReturn(Paths.get("dummy/path/to/helm").toAbsolutePath()).when(mojo).getHelmExecuteablePath(); mojo.setHelmDownloadUrl(null); mojo.setHelmVersion("3.2.0"); // run init mojo.execute(); // check helm file Path helm = Paths.get(mojo.getHelmExecutableDirectory(), "windows".equals(Os.OS_FAMILY) ? "helm.exe" : "helm") .toAbsolutePath(); assertTrue(Files.exists(helm), "Helm executable not found at: " + helm); }
Example #2
Source File: InitMojoTest.java From helm-maven-plugin with MIT License | 6 votes |
@Test public void verifyAddingStableByDefault(InitMojo mojo) throws Exception { // prepare execution ArgumentCaptor<String> helmCommandCaptor = ArgumentCaptor.forClass(String.class); doNothing().when(mojo).callCli(helmCommandCaptor.capture(), anyString(), anyBoolean()); mojo.setHelmDownloadUrl(getOsSpecificDownloadURL()); mojo.setAddDefaultRepo(true); // run init mojo.execute(); // check captured argument String helmDefaultCommand = helmCommandCaptor.getAllValues() .stream() .filter(cmd -> cmd.contains(Os.OS_FAMILY == Os.FAMILY_WINDOWS ? "helm.exe repo" : "helm repo")) .findAny().orElseThrow(() -> new IllegalArgumentException("Only one helm repo command expected")); assertTrue(helmDefaultCommand.contains("repo add stable https://kubernetes-charts.storage.googleapis.com"), "Adding stable repo by default expected"); }
Example #3
Source File: InitMojoTest.java From helm-maven-plugin with MIT License | 6 votes |
@Test public void verifyCustomConfigOptions(InitMojo mojo) throws Exception { // prepare execution ArgumentCaptor<String> helmCommandCaptor = ArgumentCaptor.forClass(String.class); doNothing().when(mojo).callCli(helmCommandCaptor.capture(), anyString(), anyBoolean()); mojo.setHelmDownloadUrl(getOsSpecificDownloadURL()); mojo.setRegistryConfig("/path/to/my/registry.json"); mojo.setRepositoryCache("/path/to/my/repository/cache"); mojo.setRepositoryConfig("/path/to/my/repositories.yaml"); mojo.setAddDefaultRepo(true); // run init mojo.execute(); // check captured argument List<String> helmCommands = helmCommandCaptor.getAllValues() .stream() .filter(cmd -> cmd.contains(Os.OS_FAMILY == Os.FAMILY_WINDOWS ? "helm.exe " : "helm ")) .collect(Collectors.toList()); assertEquals(1, helmCommands.size(), "Only helm init command expected"); String helmDefaultCommand = helmCommands.get(0); assertTrue(helmDefaultCommand.contains("--registry-config /path/to/my/registry.json"), "Option 'registry-config' not set"); assertTrue(helmDefaultCommand.contains("--repository-cache /path/to/my/repository/cache"), "Option 'repository-cache' not set"); assertTrue(helmDefaultCommand.contains("--repository-config /path/to/my/repositories.yaml"), "Option 'repository-config' not set"); }
Example #4
Source File: AbstractCompiler.java From maven-native with MIT License | 6 votes |
/** * return "obj" or "o" when file extension is not given based on current platform * * @return */ protected static String getObjectFileExtension( String fileExtension ) { if ( fileExtension != null ) { return fileExtension; } else { if ( Os.isFamily( "windows" ) ) { return "obj"; } else { return "o"; } } }
Example #5
Source File: InitMojo.java From helm-maven-plugin with MIT License | 5 votes |
private String getOperatingSystem() { switch (Os.OS_FAMILY) { case Os.FAMILY_UNIX: return "linux"; case Os.FAMILY_MAC: return "darwin"; case Os.FAMILY_WINDOWS: return "windows"; default: throw new IllegalStateException("Unsupported OS: " + Os.OS_FAMILY); } }
Example #6
Source File: InitMojoTest.java From helm-maven-plugin with MIT License | 5 votes |
private String getOsSpecificDownloadURL() { String osForDownload; switch (Os.OS_FAMILY) { case Os.FAMILY_UNIX: osForDownload = "linux"; break; case Os.FAMILY_MAC: osForDownload = "darwin"; break; default: osForDownload = Os.OS_FAMILY; } return getOsSpecificDownloadURL(osForDownload); }
Example #7
Source File: RegQueryTest.java From maven-native with MIT License | 5 votes |
public void testRegQuery() { if ( Os.isFamily( "windows" ) ) { String value = RegQuery.getValue( "REG_SZ", "HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion", "ProgramFilesDir" ); assertNotNull( value ); } }
Example #8
Source File: FileSystemUtilities.java From jaxb2-maven-plugin with Apache License 2.0 | 5 votes |
private static void validateFileOrDirectoryName(final File fileOrDir) { if (Os.isFamily(Os.FAMILY_WINDOWS) && !FileUtils.isValidWindowsFileName(fileOrDir)) { throw new IllegalArgumentException( "The file (" + fileOrDir + ") cannot contain any of the following characters: \n" + StringUtils.join(INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME, " ")); } }
Example #9
Source File: JarTest.java From takari-lifecycle with Eclipse Public License 1.0 | 5 votes |
@Test public void testSymlinkedDirectories() throws Exception { Assume.assumeTrue(Os.isFamily(Os.FAMILY_UNIX)); File basedir = resources.getBasedir(); File orig = new File(basedir, "orig"); create(orig, "src/main/java/pkg/Class.java"); create(orig, "src/test/java/testpkg/Test.java"); create(orig, "target/classes/resource.txt", "target/classes/subdir/resource.txt"); java.nio.file.Files.createSymbolicLink(new File(orig, "target/classes/symlinked-resource.txt").toPath(), new File(orig, "target/classes/resource.txt").toPath()); create(orig, "target/test-classes/test-resource.txt"); File symlink = java.nio.file.Files.createSymbolicLink(new File(basedir, "symlink").toPath(), orig.toPath()).toFile(); mojos.executeMojo(symlink, "jar", newParameter("testJar", "true"), newParameter("sourceJar", "true")); assertZipEntries(new File(symlink, "target/test-1.jar") // , "D META-INF/ 315561600000" // , "F META-INF/MANIFEST.MF 315561600000" // , "D META-INF/maven/ 315561600000" // , "D META-INF/maven/test/ 315561600000" // , "D META-INF/maven/test/test/ 315561600000" // , "F META-INF/maven/test/test/pom.properties 315561600000" // , "F resource.txt 315561600000" // , "D subdir/ 315561600000" // , "F subdir/resource.txt 315561600000" // , "F symlinked-resource.txt 315561600000" // ); assertZipEntries(new File(symlink, "target/test-1-tests.jar") // , "D META-INF/ 315561600000" // , "F META-INF/MANIFEST.MF 315561600000" // , "F test-resource.txt 315561600000" // ); assertZipEntries(new File(symlink, "target/test-1-sources.jar") // , "D META-INF/ 315561600000" // , "F META-INF/MANIFEST.MF 315561600000" // , "D pkg/ 315561600000" // , "F pkg/Class.java 315561600000" // ); }
Example #10
Source File: ExportPackageMojoTest.java From takari-lifecycle with Eclipse Public License 1.0 | 5 votes |
@Test public void testBasic_symlinked() throws Exception { Assume.assumeTrue(Os.isFamily(Os.FAMILY_UNIX)); File basedir = resources.getBasedir(); File orig = new File(basedir, "orig"); create(orig, "target/classes/exported/Class.class"); File symlink = java.nio.file.Files.createSymbolicLink(new File(basedir, "symlink").toPath(), orig.toPath()).toFile(); mojos.executeMojo(symlink, "export-package"); assertExportedPackages(symlink, "exported"); }
Example #11
Source File: ArchiveEntryUtils.java From TarsJava with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static void chmod(final File file, final int mode, final Log logger, boolean useJvmChmod) throws ArchiverException { if (!Os.isFamily(Os.FAMILY_UNIX)) { return; } final String m = Integer.toOctalString(mode & 0xfff); if (useJvmChmod && !jvmFilePermAvailable) { logger.info("chmod it's not possible where your current jvm"); useJvmChmod = false; } if (useJvmChmod && jvmFilePermAvailable) { applyPermissionsWithJvm(file, m, logger); return; } try { final Commandline commandline = new Commandline(); commandline.setWorkingDirectory(file.getParentFile().getAbsolutePath()); if (logger.isDebugEnabled()) { logger.debug(file + ": mode " + Integer.toOctalString(mode) + ", chmod " + m); } commandline.setExecutable("chmod"); commandline.createArg().setValue(m); final String path = file.getAbsolutePath(); commandline.createArg().setValue(path); final CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); final CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer(); final int exitCode = CommandLineUtils.executeCommandLine(commandline, stderr, stdout); if (exitCode != 0) { logger.warn("-------------------------------"); logger.warn("Standard error:"); logger.warn("-------------------------------"); logger.warn(stderr.getOutput()); logger.warn("-------------------------------"); logger.warn("Standard output:"); logger.warn("-------------------------------"); logger.warn(stdout.getOutput()); logger.warn("-------------------------------"); throw new ArchiverException("chmod exit code was: " + exitCode); } } catch (final CommandLineException e) { throw new ArchiverException("Error while executing chmod.", e); } }
Example #12
Source File: InitMojo.java From helm-maven-plugin with MIT License | 4 votes |
private String getExtension() { return Os.OS_FAMILY.equals(Os.FAMILY_WINDOWS) ? "zip" : "tar.gz"; }