├── .gitattributes ├── .github ├── dependabot.yml ├── release-drafter.yml └── workflows │ ├── maven.yml │ └── release-drafter.yml ├── .gitignore ├── LICENSE.txt ├── NOTICE.txt ├── README.md ├── pom.xml └── src ├── main ├── java │ └── org │ │ └── codehaus │ │ └── plexus │ │ └── util │ │ ├── AbstractScanner.java │ │ ├── Base64.java │ │ ├── BaseFileUtils.java │ │ ├── BaseIOUtil.java │ │ ├── CachedMap.java │ │ ├── CollectionUtils.java │ │ ├── DirectoryScanner.java │ │ ├── DirectoryWalkListener.java │ │ ├── DirectoryWalker.java │ │ ├── ExceptionUtils.java │ │ ├── Expand.java │ │ ├── FastMap.java │ │ ├── FileUtils.java │ │ ├── IOUtil.java │ │ ├── InterpolationFilterReader.java │ │ ├── LineOrientedInterpolatingReader.java │ │ ├── MatchPattern.java │ │ ├── MatchPatterns.java │ │ ├── NioFiles.java │ │ ├── Os.java │ │ ├── PathTool.java │ │ ├── PropertyUtils.java │ │ ├── ReaderFactory.java │ │ ├── ReflectionUtils.java │ │ ├── Scanner.java │ │ ├── SelectorUtils.java │ │ ├── StringInputStream.java │ │ ├── StringOutputStream.java │ │ ├── StringUtils.java │ │ ├── SweeperPool.java │ │ ├── TypeFormat.java │ │ ├── WriterFactory.java │ │ ├── cli │ │ ├── AbstractStreamHandler.java │ │ ├── Arg.java │ │ ├── CommandLineCallable.java │ │ ├── CommandLineException.java │ │ ├── CommandLineTimeOutException.java │ │ ├── CommandLineUtils.java │ │ ├── Commandline.java │ │ ├── DefaultConsumer.java │ │ ├── EnhancedStringTokenizer.java │ │ ├── ShutdownHookUtils.java │ │ ├── StreamConsumer.java │ │ ├── StreamFeeder.java │ │ ├── StreamPumper.java │ │ ├── WriterStreamConsumer.java │ │ └── shell │ │ │ ├── BourneShell.java │ │ │ ├── CmdShell.java │ │ │ ├── CommandShell.java │ │ │ └── Shell.java │ │ ├── dag │ │ ├── CycleDetectedException.java │ │ ├── CycleDetector.java │ │ ├── DAG.java │ │ ├── TopologicalSorter.java │ │ └── Vertex.java │ │ ├── introspection │ │ ├── ClassMap.java │ │ ├── MethodMap.java │ │ └── ReflectionValueExtractor.java │ │ ├── io │ │ ├── CachingOutputStream.java │ │ ├── CachingWriter.java │ │ ├── InputStreamFacade.java │ │ ├── RawInputStreamFacade.java │ │ └── URLInputStreamFacade.java │ │ └── reflection │ │ ├── Reflector.java │ │ └── ReflectorException.java ├── java10 │ └── org │ │ └── codehaus │ │ └── plexus │ │ └── util │ │ └── BaseIOUtil.java ├── java11 │ └── org │ │ └── codehaus │ │ └── plexus │ │ └── util │ │ └── BaseFileUtils.java ├── java9 │ └── org │ │ └── codehaus │ │ └── plexus │ │ └── util │ │ └── BaseIOUtil.java ├── javadoc │ └── org │ │ └── codehaus │ │ └── plexus │ │ └── util │ │ ├── cli │ │ ├── package.html │ │ └── shell │ │ │ └── package.html │ │ ├── dag │ │ └── package.html │ │ ├── introspection │ │ └── package.html │ │ ├── io │ │ └── package.html │ │ ├── package.html │ │ └── reflection │ │ └── package.html └── resources │ ├── META-INF │ ├── LICENSE │ └── NOTICE │ └── licenses │ ├── extreme.indiana.edu.license.TXT │ ├── javolution.license.TXT │ └── thoughtworks.TXT ├── site ├── markdown │ └── index.md └── site.xml └── test ├── java └── org │ └── codehaus │ └── plexus │ └── util │ ├── AbstractTestThread.java │ ├── CollectionUtilsTest.java │ ├── DirectoryScannerTest.java │ ├── DirectoryWalkerTest.java │ ├── FileBasedTestCase.java │ ├── FileUtilsTest.java │ ├── IOUtilTest.java │ ├── InterpolationFilterReaderTest.java │ ├── LineOrientedInterpolatingReaderTest.java │ ├── MatchPatternTest.java │ ├── MatchPatternsTest.java │ ├── OsTest.java │ ├── PathToolTest.java │ ├── PerfTest.java │ ├── ReflectionUtilsTest.java │ ├── SelectorUtilsTest.java │ ├── StringUtilsTest.java │ ├── SweeperPoolTest.java │ ├── TestThreadManager.java │ ├── Tracer.java │ ├── WalkCollector.java │ ├── cli │ ├── CommandLineUtilsTest.java │ ├── CommandlineTest.java │ ├── DefaultConsumerTest.java │ ├── EnhancedStringTokenizerTest.java │ ├── StreamPumperTest.java │ └── shell │ │ └── BourneShellTest.java │ ├── dag │ ├── CycleDetectedExceptionTest.java │ ├── CycleDetectorTest.java │ ├── DAGTest.java │ ├── TopologicalSorterTest.java │ └── VertexTest.java │ ├── introspection │ └── ReflectionValueExtractorTest.java │ ├── io │ ├── CachingOutputStreamTest.java │ └── CachingWriterTest.java │ └── reflection │ └── ReflectorTest.java └── resources ├── dir-layout-copy ├── dir1 │ ├── dir2 │ │ └── .gitignore │ └── foo.txt └── empty-dir │ └── .gitignore ├── directory-scanner └── foo │ └── bar │ └── munchy.txt ├── directorywalker ├── directory1 │ └── file1.txt ├── directory2 │ ├── directory21 │ │ └── file21.txt │ └── file2.txt └── file.txt ├── symlinks ├── dirOnTheOutside │ └── FileInDirOnTheOutside.txt ├── onTheOutside.txt ├── regen.sh ├── src │ ├── aRegularDir │ │ └── aRegularFile.txt │ ├── fileR.txt │ ├── fileW.txt │ ├── fileX.txt │ ├── symDir │ ├── symLinkToDirOnTheOutside │ ├── symLinkToFileOnTheOutside │ ├── symR │ ├── symW │ ├── symX │ └── targetDir │ │ └── targetFile.txt ├── symlinks.tar └── symlinks.zip ├── test.txt ├── test.xdoc.xhtml └── testDocument.xhtml /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | *.java text diff=java 5 | *.html text diff=html 6 | *.css text 7 | *.js text 8 | *.sql text 9 | 10 | # some files require the correct eol for proper testing 11 | *-DOS.xml text eol=crlf 12 | *-UNIX.xml text eol=lf 13 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "maven" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | - package-ecosystem: "github-actions" 8 | directory: "/" 9 | schedule: 10 | interval: "daily" 11 | - package-ecosystem: "maven" 12 | directory: "/" 13 | schedule: 14 | interval: "daily" 15 | target-branch: "plexus-utils-3.x" 16 | -------------------------------------------------------------------------------- /.github/release-drafter.yml: -------------------------------------------------------------------------------- 1 | _extends: .github 2 | tag-template: plexus-utils-$NEXT_MINOR_VERSION 3 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | name: GitHub CI 19 | 20 | on: [push, pull_request] 21 | 22 | jobs: 23 | build: 24 | name: Build it 25 | uses: codehaus-plexus/.github/.github/workflows/maven.yml@master 26 | 27 | deploy: 28 | name: Deploy 29 | needs: build 30 | uses: codehaus-plexus/.github/.github/workflows/maven-deploy.yml@master 31 | secrets: inherit 32 | -------------------------------------------------------------------------------- /.github/workflows/release-drafter.yml: -------------------------------------------------------------------------------- 1 | name: Release Drafter 2 | on: 3 | push: 4 | branches: 5 | - master 6 | jobs: 7 | update_release_draft: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: release-drafter/release-drafter@v6 11 | env: 12 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .project 3 | .classpath 4 | .settings/ 5 | bin 6 | *.iml 7 | *.ipr 8 | *.iws 9 | *.idea 10 | release.properties 11 | .java-version 12 | 13 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | This product includes software developed by 2 | The Apache Software Foundation (http://www.apache.org/). 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Plexus-Utils 2 | ============ 3 | 4 | [![Build Status](https://github.com/codehaus-plexus/plexus-utils/actions/workflows/maven.yml/badge.svg)](https://github.com/codehaus-plexus/plexus-utils/actions) 5 | [![Maven Central](https://img.shields.io/maven-central/v/org.codehaus.plexus/plexus-utils.svg?label=Maven%20Central)](https://search.maven.org/artifact/org.codehaus.plexus/plexus-utils) 6 | [![Reproducible Builds](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/jvm-repo-rebuild/reproducible-central/master/content/org/codehaus/plexus/plexus-utils/badge.json)](https://github.com/jvm-repo-rebuild/reproducible-central/blob/master/content/org/codehaus/plexus/plexus-utils/README.md) 7 | 8 | This library is historically used by the Apache Maven project so it's developed and maintained by the same [`bad guys`](http://maven.apache.org/team.html) 9 | 10 | The current master is now at https://github.com/codehaus-plexus/plexus-utils 11 | 12 | For publishing [the site](https://codehaus-plexus.github.io/plexus-utils/) do the following: 13 | 14 | ``` 15 | mvn -Preporting verify site site:stage scm-publish:publish-scm 16 | ``` 17 | 18 | Starting with version 4, XML classes (in `org.codehaus.plexus.util.xml` and `org.codehaus.plexus.util.xml.pull`) have been extracted to a separate [`plexus-xml`](https://github.com/codehaus-plexus/plexus-xml/) library: if you need them, just use this new artifact. 19 | 20 | `plexus-utils` 4 keeps an optional dependency on `plexus-xml` 3 to keep compatibility with the few XML-oriented methods of `ReaderFactory` and `WriterFactory`: these classes are deprecated, you should migrate as explained in javadoc. And keep `plexus-xml` to 3 if you want Maven 3 compatibility, as `plexus-xml` 4 works only in Maven 4. 21 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/BaseFileUtils.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.Files; 5 | import java.nio.file.OpenOption; 6 | import java.nio.file.Path; 7 | 8 | /** 9 | * Implementation specific to Java SE 8 version. 10 | */ 11 | abstract class BaseFileUtils { 12 | static String fileRead(Path path, String encoding) throws IOException { 13 | byte[] bytes = Files.readAllBytes(path); 14 | return encoding != null ? new String(bytes, encoding) : new String(bytes); 15 | } 16 | 17 | static void fileWrite(Path path, String encoding, String data, OpenOption... openOptions) throws IOException { 18 | byte[] bytes = encoding != null ? data.getBytes(encoding) : data.getBytes(); 19 | Files.write(path, bytes, openOptions); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/BaseIOUtil.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.io.OutputStream; 6 | import java.io.Reader; 7 | import java.io.Writer; 8 | 9 | /** 10 | * Implementation specific to Java SE 8 version. 11 | */ 12 | abstract class BaseIOUtil { 13 | private static final int DEFAULT_BUFFER_SIZE = 1024 * 16; 14 | 15 | static void copy(final InputStream input, final OutputStream output) throws IOException { 16 | IOUtil.copy(input, output, DEFAULT_BUFFER_SIZE); 17 | } 18 | 19 | static void copy(final Reader input, final Writer output) throws IOException { 20 | IOUtil.copy(input, output, DEFAULT_BUFFER_SIZE); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/DirectoryWalkListener.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.io.File; 20 | 21 | /** 22 | * Observes the actions of a {@link DirectoryWalker}. 23 | * 24 | * 25 | * @see DirectoryWalker 26 | */ 27 | public interface DirectoryWalkListener { 28 | /** 29 | * The directory walking has begun. 30 | * 31 | * @param basedir the basedir that walk started in. 32 | */ 33 | void directoryWalkStarting(File basedir); 34 | 35 | /** 36 | * The included entry that was encountered. 37 | * 38 | * @param percentage rough percentage of the walk completed. (inaccurate) 39 | * @param file the file that was included. 40 | */ 41 | void directoryWalkStep(int percentage, File file); 42 | 43 | /** 44 | * The directory walking has finished. 45 | */ 46 | void directoryWalkFinished(); 47 | 48 | void debug(String message); 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/Expand.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | /* 4 | * The Apache Software License, Version 1.1 5 | * 6 | * Copyright (c) 2000-2002 The Apache Software Foundation. All rights 7 | * reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in 18 | * the documentation and/or other materials provided with the 19 | * distribution. 20 | * 21 | * 3. The end-user documentation included with the redistribution, if 22 | * any, must include the following acknowledgement: 23 | * "This product includes software developed by the 24 | * Apache Software Foundation (http://www.codehaus.org/)." 25 | * Alternately, this acknowledgement may appear in the software itself, 26 | * if and wherever such third-party acknowledgements normally appear. 27 | * 28 | * 4. The names "The Jakarta Project", "Ant", and "Apache Software 29 | * Foundation" must not be used to endorse or promote products derived 30 | * from this software without prior written permission. For written 31 | * permission, please contact codehaus@codehaus.org. 32 | * 33 | * 5. Products derived from this software may not be called "Apache" 34 | * nor may "Apache" appear in their names without prior written 35 | * permission of the Apache Group. 36 | * 37 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 38 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 39 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 40 | * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 43 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 44 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 45 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 46 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 47 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 48 | * SUCH DAMAGE. 49 | * ==================================================================== 50 | * 51 | * This software consists of voluntary contributions made by many 52 | * individuals on behalf of the Apache Software Foundation. For more 53 | * information on the Apache Software Foundation, please see 54 | * . 55 | */ 56 | 57 | import java.io.File; 58 | import java.io.FileNotFoundException; 59 | import java.io.IOException; 60 | import java.io.InputStream; 61 | import java.io.OutputStream; 62 | import java.nio.file.Files; 63 | import java.util.Date; 64 | import java.util.zip.ZipEntry; 65 | import java.util.zip.ZipInputStream; 66 | 67 | /** 68 | * Unzip a file. 69 | * 70 | * @author costin@dnt.ro 71 | * @author Stefan Bodewig 72 | * @author Magesh Umasankar 73 | * @since Ant 1.1 @ant.task category="packaging" name="unzip" name="unjar" name="unwar" 74 | * 75 | */ 76 | public class Expand { 77 | 78 | private File dest; // req 79 | 80 | private File source; // req 81 | 82 | private boolean overwrite = true; 83 | 84 | /** 85 | * Do the work. 86 | * 87 | * @exception Exception Thrown in unrecoverable error. 88 | */ 89 | public void execute() throws Exception { 90 | expandFile(source, dest); 91 | } 92 | 93 | protected void expandFile(final File srcF, final File dir) throws Exception { 94 | // code from WarExpand 95 | try (ZipInputStream zis = new ZipInputStream(Files.newInputStream(srcF.toPath()))) { 96 | for (ZipEntry ze = zis.getNextEntry(); ze != null; ze = zis.getNextEntry()) { 97 | extractFile(srcF, dir, zis, ze.getName(), new Date(ze.getTime()), ze.isDirectory()); 98 | } 99 | } catch (IOException ioe) { 100 | throw new Exception("Error while expanding " + srcF.getPath(), ioe); 101 | } 102 | } 103 | 104 | protected void extractFile( 105 | File srcF, 106 | File dir, 107 | InputStream compressedInputStream, 108 | String entryName, 109 | Date entryDate, 110 | boolean isDirectory) 111 | throws Exception { 112 | File f = FileUtils.resolveFile(dir, entryName); 113 | 114 | if (!f.getAbsolutePath().startsWith(dir.getAbsolutePath())) { 115 | throw new IOException("Entry '" + entryName + "' outside the target directory."); 116 | } 117 | 118 | try { 119 | if (!overwrite && f.exists() && f.lastModified() >= entryDate.getTime()) { 120 | return; 121 | } 122 | 123 | // create intermediary directories - sometimes zip don't add them 124 | File dirF = f.getParentFile(); 125 | dirF.mkdirs(); 126 | 127 | if (isDirectory) { 128 | f.mkdirs(); 129 | } else { 130 | byte[] buffer = new byte[65536]; 131 | 132 | try (OutputStream fos = Files.newOutputStream(f.toPath())) { 133 | for (int length = compressedInputStream.read(buffer); 134 | length >= 0; 135 | fos.write(buffer, 0, length), length = compressedInputStream.read(buffer)) 136 | ; 137 | } 138 | } 139 | 140 | f.setLastModified(entryDate.getTime()); 141 | } catch (FileNotFoundException ex) { 142 | throw new Exception("Can't extract file " + srcF.getPath(), ex); 143 | } 144 | } 145 | 146 | /** 147 | * Set the destination directory. File will be unzipped into the destination directory. 148 | * 149 | * @param d Path to the directory. 150 | */ 151 | public void setDest(File d) { 152 | this.dest = d; 153 | } 154 | 155 | /** 156 | * Set the path to zip-file. 157 | * 158 | * @param s Path to zip-file. 159 | */ 160 | public void setSrc(File s) { 161 | this.source = s; 162 | } 163 | 164 | /** 165 | * @param b Should we overwrite files in dest, even if they are newer than the corresponding entries in the archive? 166 | */ 167 | public void setOverwrite(boolean b) { 168 | overwrite = b; 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/MatchPattern.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.io.File; 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | import java.util.StringTokenizer; 23 | 24 | /** 25 | *

Describes a match target for SelectorUtils.

26 | * 27 | *

Significantly more efficient than using strings, since re-evaluation and re-tokenizing is avoided.

28 | * 29 | * @author Kristian Rosenvold 30 | */ 31 | public class MatchPattern { 32 | private final String source; 33 | 34 | private final String regexPattern; 35 | 36 | private final String separator; 37 | 38 | private final String[] tokenized; 39 | 40 | private final char[][] tokenizedChar; 41 | 42 | private MatchPattern(String source, String separator) { 43 | regexPattern = SelectorUtils.isRegexPrefixedPattern(source) 44 | ? source.substring( 45 | SelectorUtils.REGEX_HANDLER_PREFIX.length(), 46 | source.length() - SelectorUtils.PATTERN_HANDLER_SUFFIX.length()) 47 | : null; 48 | this.source = SelectorUtils.isAntPrefixedPattern(source) 49 | ? source.substring( 50 | SelectorUtils.ANT_HANDLER_PREFIX.length(), 51 | source.length() - SelectorUtils.PATTERN_HANDLER_SUFFIX.length()) 52 | : source; 53 | this.separator = separator; 54 | tokenized = tokenizePathToString(this.source, separator); 55 | tokenizedChar = new char[tokenized.length][]; 56 | for (int i = 0; i < tokenized.length; i++) { 57 | tokenizedChar[i] = tokenized[i].toCharArray(); 58 | } 59 | } 60 | 61 | /** 62 | * Gets the source pattern for this match pattern. 63 | * @return the source string without Ant or Regex pattern markers. 64 | */ 65 | public String getSource() { 66 | return regexPattern == null ? source : regexPattern; 67 | } 68 | 69 | public boolean matchPath(String str, boolean isCaseSensitive) { 70 | if (regexPattern != null) { 71 | return str.matches(regexPattern); 72 | } else { 73 | return SelectorUtils.matchAntPathPattern(this, str, separator, isCaseSensitive); 74 | } 75 | } 76 | 77 | boolean matchPath(String str, char[][] strDirs, boolean isCaseSensitive) { 78 | if (regexPattern != null) { 79 | return str.matches(regexPattern); 80 | } else { 81 | return SelectorUtils.matchAntPathPattern(getTokenizedPathChars(), strDirs, isCaseSensitive); 82 | } 83 | } 84 | 85 | public boolean matchPatternStart(String str, boolean isCaseSensitive) { 86 | if (regexPattern != null) { 87 | // FIXME: ICK! But we can't do partial matches for regex, so we have to reserve judgement until we have 88 | // a file to deal with, or we can definitely say this is an exclusion... 89 | return true; 90 | } else { 91 | String altStr = str.replace('\\', '/'); 92 | 93 | return SelectorUtils.matchAntPathPatternStart(this, str, File.separator, isCaseSensitive) 94 | || SelectorUtils.matchAntPathPatternStart(this, altStr, "/", isCaseSensitive); 95 | } 96 | } 97 | 98 | public String[] getTokenizedPathString() { 99 | return tokenized; 100 | } 101 | 102 | public char[][] getTokenizedPathChars() { 103 | return tokenizedChar; 104 | } 105 | 106 | public boolean startsWith(String string) { 107 | return source.startsWith(string); 108 | } 109 | 110 | public static String[] tokenizePathToString(String path, String separator) { 111 | List ret = new ArrayList(); 112 | StringTokenizer st = new StringTokenizer(path, separator); 113 | while (st.hasMoreTokens()) { 114 | ret.add(st.nextToken()); 115 | } 116 | return ret.toArray(new String[0]); 117 | } 118 | 119 | static char[][] tokenizePathToCharArray(String path, String separator) { 120 | String[] tokenizedName = tokenizePathToString(path, separator); 121 | char[][] tokenizedNameChar = new char[tokenizedName.length][]; 122 | for (int i = 0; i < tokenizedName.length; i++) { 123 | tokenizedNameChar[i] = tokenizedName[i].toCharArray(); 124 | } 125 | return tokenizedNameChar; 126 | } 127 | 128 | public static MatchPattern fromString(String source) { 129 | return new MatchPattern(source, File.separator); 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/MatchPatterns.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | import java.io.File; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | /** 8 | * A list of patterns to be matched 9 | * 10 | * @author Kristian Rosenvold 11 | */ 12 | public class MatchPatterns { 13 | private final MatchPattern[] patterns; 14 | 15 | private MatchPatterns(MatchPattern[] patterns) { 16 | this.patterns = patterns; 17 | } 18 | 19 | /** 20 | * Gets a list of enclosed MatchPattern sources. 21 | * @return A list of enclosed MatchPattern sources. 22 | */ 23 | public List getSources() { 24 | List sources = new ArrayList<>(); 25 | for (MatchPattern pattern : patterns) { 26 | sources.add(pattern.getSource()); 27 | } 28 | return sources; 29 | } 30 | 31 | /** 32 | *

Checks these MatchPatterns against a specified string.

33 | * 34 | *

Uses far less string tokenization than any of the alternatives.

35 | * 36 | * @param name The name to look for 37 | * @param isCaseSensitive If the comparison is case sensitive 38 | * @return true if any of the supplied patterns match 39 | */ 40 | public boolean matches(String name, boolean isCaseSensitive) { 41 | String[] tokenized = MatchPattern.tokenizePathToString(name, File.separator); 42 | return matches(name, tokenized, isCaseSensitive); 43 | } 44 | 45 | public boolean matches(String name, String[] tokenizedName, boolean isCaseSensitive) { 46 | char[][] tokenizedNameChar = new char[tokenizedName.length][]; 47 | for (int i = 0; i < tokenizedName.length; i++) { 48 | tokenizedNameChar[i] = tokenizedName[i].toCharArray(); 49 | } 50 | return matches(name, tokenizedNameChar, isCaseSensitive); 51 | } 52 | 53 | public boolean matches(String name, char[][] tokenizedNameChar, boolean isCaseSensitive) { 54 | for (MatchPattern pattern : patterns) { 55 | if (pattern.matchPath(name, tokenizedNameChar, isCaseSensitive)) { 56 | return true; 57 | } 58 | } 59 | return false; 60 | } 61 | 62 | public boolean matchesPatternStart(String name, boolean isCaseSensitive) { 63 | for (MatchPattern includesPattern : patterns) { 64 | if (includesPattern.matchPatternStart(name, isCaseSensitive)) { 65 | return true; 66 | } 67 | } 68 | return false; 69 | } 70 | 71 | public static MatchPatterns from(String... sources) { 72 | final int length = sources.length; 73 | MatchPattern[] result = new MatchPattern[length]; 74 | for (int i = 0; i < length; i++) { 75 | result[i] = MatchPattern.fromString(sources[i]); 76 | } 77 | return new MatchPatterns(result); 78 | } 79 | 80 | public static MatchPatterns from(Iterable strings) { 81 | return new MatchPatterns(getMatchPatterns(strings)); 82 | } 83 | 84 | private static MatchPattern[] getMatchPatterns(Iterable items) { 85 | List result = new ArrayList(); 86 | for (String string : items) { 87 | result.add(MatchPattern.fromString(string)); 88 | } 89 | return result.toArray(new MatchPattern[0]); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/NioFiles.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | /* 4 | * Copyright 2007 The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.io.File; 20 | import java.io.IOException; 21 | import java.nio.file.Files; 22 | import java.nio.file.LinkOption; 23 | import java.nio.file.Path; 24 | import java.nio.file.StandardCopyOption; 25 | import java.nio.file.attribute.BasicFileAttributes; 26 | import java.nio.file.attribute.PosixFilePermission; 27 | import java.util.HashSet; 28 | import java.util.Set; 29 | 30 | /** 31 | * Encapsulates use of java7 features, exposing mostly backward compatible types 32 | */ 33 | @SuppressWarnings("Since15") 34 | public class NioFiles { 35 | public static boolean isSymbolicLink(File file) { 36 | return Files.isSymbolicLink(file.toPath()); 37 | } 38 | 39 | public static void chmod(File file, int mode) throws IOException { 40 | Path path = file.toPath(); 41 | if (!Files.isSymbolicLink(path)) { 42 | Files.setPosixFilePermissions(path, getPermissions(mode)); 43 | } 44 | } 45 | 46 | @SuppressWarnings({"OctalInteger", "MagicNumber"}) 47 | private static Set getPermissions(int mode) { 48 | Set perms = new HashSet<>(); 49 | // add owners permission 50 | if ((mode & 0400) > 0) { 51 | perms.add(PosixFilePermission.OWNER_READ); 52 | } 53 | if ((mode & 0200) > 0) { 54 | perms.add(PosixFilePermission.OWNER_WRITE); 55 | } 56 | if ((mode & 0100) > 0) { 57 | perms.add(PosixFilePermission.OWNER_EXECUTE); 58 | } 59 | // add group permissions 60 | if ((mode & 0040) > 0) { 61 | perms.add(PosixFilePermission.GROUP_READ); 62 | } 63 | if ((mode & 0020) > 0) { 64 | perms.add(PosixFilePermission.GROUP_WRITE); 65 | } 66 | if ((mode & 0010) > 0) { 67 | perms.add(PosixFilePermission.GROUP_EXECUTE); 68 | } 69 | // add others permissions 70 | if ((mode & 0004) > 0) { 71 | perms.add(PosixFilePermission.OTHERS_READ); 72 | } 73 | if ((mode & 0002) > 0) { 74 | perms.add(PosixFilePermission.OTHERS_WRITE); 75 | } 76 | if ((mode & 0001) > 0) { 77 | perms.add(PosixFilePermission.OTHERS_EXECUTE); 78 | } 79 | return perms; 80 | } 81 | 82 | public static long getLastModified(File file) throws IOException { 83 | BasicFileAttributes basicFileAttributes = Files.readAttributes(file.toPath(), BasicFileAttributes.class); 84 | return basicFileAttributes.lastModifiedTime().toMillis(); 85 | } 86 | 87 | /** 88 | * Reads the target of the symbolic link 89 | * 90 | * @param symlink A file that is a symlink 91 | * @return A file that is the target of the symlink 92 | * @throws java.io.IOException io issue 93 | */ 94 | public static File readSymbolicLink(File symlink) throws IOException { 95 | Path path = Files.readSymbolicLink(symlink.toPath()); 96 | return path.toFile(); 97 | } 98 | 99 | public static File createSymbolicLink(File symlink, File target) throws IOException { 100 | Path link = symlink.toPath(); 101 | if (Files.exists(link, LinkOption.NOFOLLOW_LINKS)) { 102 | Files.delete(link); 103 | } 104 | link = Files.createSymbolicLink(link, target.toPath()); 105 | return link.toFile(); 106 | } 107 | 108 | public static boolean deleteIfExists(File file) throws IOException { 109 | return Files.deleteIfExists(file.toPath()); 110 | } 111 | 112 | public static File copy(File source, File target) throws IOException { 113 | Path copy = Files.copy( 114 | source.toPath(), 115 | target.toPath(), 116 | StandardCopyOption.REPLACE_EXISTING, 117 | StandardCopyOption.COPY_ATTRIBUTES); 118 | return copy.toFile(); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/PropertyUtils.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.io.File; 20 | import java.io.IOException; 21 | import java.io.InputStream; 22 | import java.net.URL; 23 | import java.nio.file.Files; 24 | import java.util.Objects; 25 | import java.util.Properties; 26 | 27 | /** 28 | * Static methods to create Properties loaded from various sources. 29 | * 30 | * @author Jason van Zyl 31 | * @author Michal Maczka 32 | */ 33 | public class PropertyUtils { 34 | 35 | public static Properties loadProperties(final URL url) throws IOException { 36 | return loadProperties(Objects.requireNonNull(url, "url").openStream()); 37 | } 38 | 39 | public static Properties loadProperties(final File file) throws IOException { 40 | return loadProperties( 41 | Files.newInputStream(Objects.requireNonNull(file, "file").toPath())); 42 | } 43 | 44 | public static Properties loadProperties(final InputStream is) throws IOException { 45 | final Properties properties = new Properties(); 46 | 47 | // Make sure the properties stream is valid 48 | if (is != null) { 49 | try (InputStream in = is) { 50 | properties.load(in); 51 | } 52 | } 53 | 54 | return properties; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/Scanner.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.io.File; 20 | import java.util.Comparator; 21 | 22 | /** 23 | * Scan a directory tree for files, with specified inclusions and exclusions. 24 | */ 25 | public interface Scanner { 26 | 27 | /** 28 | * Sets the list of include patterns to use. All '/' and '\' characters are replaced by 29 | * File.separatorChar, so the separator used need not match File.separatorChar. 30 | *

31 | * When a pattern ends with a '/' or '\', "**" is appended. 32 | * 33 | * @param includes A list of include patterns. May be null, indicating that all files should be 34 | * included. If a non-null list is given, all elements must be non-null. 35 | */ 36 | void setIncludes(String[] includes); 37 | 38 | /** 39 | * Sets the list of exclude patterns to use. All '/' and '\' characters are replaced by 40 | * File.separatorChar, so the separator used need not match File.separatorChar. 41 | *

42 | * When a pattern ends with a '/' or '\', "**" is appended. 43 | * 44 | * @param excludes A list of exclude patterns. May be null, indicating that no files should be 45 | * excluded. If a non-null list is given, all elements must be non-null. 46 | */ 47 | void setExcludes(String[] excludes); 48 | 49 | /** 50 | * Adds default exclusions to the current exclusions set. 51 | */ 52 | void addDefaultExcludes(); 53 | 54 | /** 55 | * Scans the base directory for files which match at least one include pattern and don't match any exclude patterns. 56 | * 57 | * @exception IllegalStateException if the base directory was set incorrectly (i.e. if it is null, 58 | * doesn't exist, or isn't a directory). 59 | */ 60 | void scan(); 61 | 62 | /** 63 | * Returns the names of the files which matched at least one of the include patterns and none of the exclude 64 | * patterns. The names are relative to the base directory. 65 | * 66 | * @return the names of the files which matched at least one of the include patterns and none of the exclude 67 | * patterns. 68 | */ 69 | String[] getIncludedFiles(); 70 | 71 | /** 72 | * Returns the names of the directories which matched at least one of the include patterns and none of the exclude 73 | * patterns. The names are relative to the base directory. 74 | * 75 | * @return the names of the directories which matched at least one of the include patterns and none of the exclude 76 | * patterns. 77 | */ 78 | String[] getIncludedDirectories(); 79 | 80 | /** 81 | * Returns the base directory to be scanned. This is the directory which is scanned recursively. 82 | * 83 | * @return the base directory to be scanned 84 | */ 85 | File getBasedir(); 86 | 87 | /** 88 | * Use a filename comparator in each directory when scanning. 89 | * 90 | * @param filenameComparator the Comparator instance to use 91 | * @since 3.3.0 92 | */ 93 | void setFilenameComparator(Comparator filenameComparator); 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/StringInputStream.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | /* ==================================================================== 4 | * The Apache Software License, Version 1.1 5 | * 6 | * Copyright (c) 2001 The Apache Software Foundation. All rights 7 | * reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in 18 | * the documentation and/or other materials provided with the 19 | * distribution. 20 | * 21 | * 3. The end-user documentation included with the redistribution, 22 | * if any, must include the following acknowledgment: 23 | * "This product includes software developed by the 24 | * Apache Software Foundation (http://www.codehaus.org/)." 25 | * Alternately, this acknowledgment may appear in the software itself, 26 | * if and wherever such third-party acknowledgments normally appear. 27 | * 28 | * 4. The names "Apache" and "Apache Software Foundation" and 29 | * "Apache MavenSession" must not be used to endorse or promote products 30 | * derived from this software without prior written permission. For 31 | * written permission, please contact codehaus@codehaus.org. 32 | * 33 | * 5. Products derived from this software may not be called "Apache", 34 | * "Apache MavenSession", nor may "Apache" appear in their name, without 35 | * prior written permission of the Apache Software Foundation. 36 | * 37 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 38 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 39 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 40 | * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 43 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 44 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 45 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 46 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 47 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 48 | * SUCH DAMAGE. 49 | * ==================================================================== 50 | * 51 | * This software consists of voluntary contributions made by many 52 | * individuals on behalf of the Apache Software Foundation. For more 53 | * information on the Apache Software Foundation, please see 54 | * . 55 | * 56 | * ==================================================================== 57 | */ 58 | 59 | import java.io.IOException; 60 | import java.io.InputStream; 61 | import java.io.StringReader; 62 | 63 | /** 64 | * Wraps a String as an InputStream. Note that data will be lost for characters not in ISO Latin 1, as a simple 65 | * char->byte mapping is assumed. 66 | * 67 | * @author Magesh Umasankar 68 | * @deprecated As of version 1.5.2 this class should no longer be used because it does not properly handle character 69 | * encoding. Instead, wrap the output from {@link String#getBytes(String)} into a 70 | * {@link java.io.ByteArrayInputStream}. 71 | */ 72 | @Deprecated 73 | public class StringInputStream extends InputStream { 74 | /** Source string, stored as a StringReader */ 75 | private StringReader in; 76 | 77 | /** 78 | * Composes a stream from a String 79 | * 80 | * @param source The string to read from. Must not be null. 81 | */ 82 | public StringInputStream(String source) { 83 | in = new StringReader(source); 84 | } 85 | 86 | /** 87 | * Reads from the Stringreader, returning the same value. Note that data will be lost for characters not in ISO 88 | * Latin 1. Clients assuming a return value in the range -1 to 255 may even fail on such input. 89 | * 90 | * @return the value of the next character in the StringReader 91 | * @exception IOException if the original StringReader fails to be read 92 | */ 93 | @Override 94 | public int read() throws IOException { 95 | return in.read(); 96 | } 97 | 98 | /** 99 | * Closes the Stringreader. 100 | * 101 | * @exception IOException if the original StringReader fails to be closed 102 | */ 103 | @Override 104 | public void close() throws IOException { 105 | in.close(); 106 | } 107 | 108 | /** 109 | * Marks the read limit of the StringReader. 110 | * 111 | * @param limit the maximum limit of bytes that can be read before the mark position becomes invalid 112 | */ 113 | @Override 114 | public synchronized void mark(final int limit) { 115 | try { 116 | in.mark(limit); 117 | } catch (IOException ioe) { 118 | throw new RuntimeException(ioe.getMessage()); 119 | } 120 | } 121 | 122 | /** 123 | * Resets the StringReader. 124 | * 125 | * @exception IOException if the StringReader fails to be reset 126 | */ 127 | @Override 128 | public synchronized void reset() throws IOException { 129 | in.reset(); 130 | } 131 | 132 | /** 133 | * @see InputStream#markSupported 134 | */ 135 | @Override 136 | public boolean markSupported() { 137 | return in.markSupported(); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/StringOutputStream.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.io.IOException; 20 | import java.io.OutputStream; 21 | 22 | /** 23 | * Wraps a String as an OutputStream. 24 | * 25 | * @author Emmanuel Venisse 26 | * 27 | * @deprecated As of version 1.5.2 this class should no longer be used because it does not properly handle character 28 | * encoding. Instead, use {@link java.io.ByteArrayOutputStream#toString(String)}. 29 | */ 30 | @Deprecated 31 | public class StringOutputStream extends OutputStream { 32 | private StringBuffer buf = new StringBuffer(); 33 | 34 | @Override 35 | public void write(byte[] b) throws IOException { 36 | buf.append(new String(b)); 37 | } 38 | 39 | @Override 40 | public void write(byte[] b, int off, int len) throws IOException { 41 | buf.append(new String(b, off, len)); 42 | } 43 | 44 | @Override 45 | public void write(int b) throws IOException { 46 | byte[] bytes = new byte[1]; 47 | bytes[0] = (byte) b; 48 | buf.append(new String(bytes)); 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return buf.toString(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/WriterFactory.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.io.File; 20 | import java.io.IOException; 21 | import java.io.OutputStream; 22 | import java.io.OutputStreamWriter; 23 | import java.io.UnsupportedEncodingException; 24 | import java.io.Writer; 25 | import java.nio.charset.Charset; 26 | import java.nio.file.Files; 27 | 28 | import org.codehaus.plexus.util.xml.XmlStreamWriter; 29 | 30 | /** 31 | * Utility to create Writers, with explicit encoding choice: platform default, XML, or specified. 32 | * 33 | * @deprecated This class has been deprecated. When writing XML, users can create the {@link XmlStreamWriter} instance 34 | * directly. For other usages, using {@link Files} helper methods is recommended. 35 | * 36 | * @author Herve Boutemy 37 | * @see Charset 38 | * @see Supported encodings 39 | * 40 | * @since 1.4.4 41 | */ 42 | @Deprecated 43 | public class WriterFactory { 44 | /** 45 | * ISO Latin Alphabet #1, also known as ISO-LATIN-1. Every implementation of the Java platform is required to 46 | * support this character encoding. 47 | * 48 | * @see Charset 49 | */ 50 | public static final String ISO_8859_1 = "ISO-8859-1"; 51 | 52 | /** 53 | * Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set. Every 54 | * implementation of the Java platform is required to support this character encoding. 55 | * 56 | * @see Charset 57 | */ 58 | public static final String US_ASCII = "US-ASCII"; 59 | 60 | /** 61 | * Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial byte-order mark (either 62 | * order accepted on input, big-endian used on output). Every implementation of the Java platform is required to 63 | * support this character encoding. 64 | * 65 | * @see Charset 66 | */ 67 | public static final String UTF_16 = "UTF-16"; 68 | 69 | /** 70 | * Sixteen-bit Unicode Transformation Format, big-endian byte order. Every implementation of the Java platform is 71 | * required to support this character encoding. 72 | * 73 | * @see Charset 74 | */ 75 | public static final String UTF_16BE = "UTF-16BE"; 76 | 77 | /** 78 | * Sixteen-bit Unicode Transformation Format, little-endian byte order. Every implementation of the Java platform is 79 | * required to support this character encoding. 80 | * 81 | * @see Charset 82 | */ 83 | public static final String UTF_16LE = "UTF-16LE"; 84 | 85 | /** 86 | * Eight-bit Unicode Transformation Format. Every implementation of the Java platform is required to support this 87 | * character encoding. 88 | * 89 | * @see Charset 90 | */ 91 | public static final String UTF_8 = "UTF-8"; 92 | 93 | /** 94 | * The file.encoding System Property. 95 | */ 96 | public static final String FILE_ENCODING = System.getProperty("file.encoding"); 97 | 98 | /** 99 | * Create a new Writer with XML encoding detection rules. 100 | * 101 | * @param out not null output stream. 102 | * @return an XML writer instance for the output stream. 103 | * @throws IOException if any. 104 | * @see XmlStreamWriter 105 | */ 106 | public static XmlStreamWriter newXmlWriter(OutputStream out) throws IOException { 107 | return new XmlStreamWriter(out); 108 | } 109 | 110 | /** 111 | * Create a new Writer with XML encoding detection rules. 112 | * 113 | * @param file not null file. 114 | * @return an XML writer instance for the output file. 115 | * @throws IOException if any. 116 | * @see XmlStreamWriter 117 | */ 118 | public static XmlStreamWriter newXmlWriter(File file) throws IOException { 119 | return new XmlStreamWriter(file); 120 | } 121 | 122 | /** 123 | * Create a new Writer with default platform encoding. 124 | * 125 | * @param out not null output stream. 126 | * @return a writer instance for the output stream using the default platform charset. 127 | * @see Charset#defaultCharset() 128 | */ 129 | public static Writer newPlatformWriter(OutputStream out) { 130 | return new OutputStreamWriter(out); 131 | } 132 | 133 | /** 134 | * Create a new Writer with default platform encoding. 135 | * 136 | * @param file not null file. 137 | * @return a writer instance for the output file using the default platform charset. 138 | * @throws IOException if any. 139 | * @see Charset#defaultCharset() 140 | */ 141 | public static Writer newPlatformWriter(File file) throws IOException { 142 | return Files.newBufferedWriter(file.toPath()); 143 | } 144 | 145 | /** 146 | * Create a new Writer with specified encoding. 147 | * 148 | * @param out not null output stream. 149 | * @param encoding not null supported encoding. 150 | * @return a writer instance for the output stream using the given encoding. 151 | * @throws UnsupportedEncodingException if any. 152 | * @see Supported encodings 153 | */ 154 | public static Writer newWriter(OutputStream out, String encoding) throws UnsupportedEncodingException { 155 | return new OutputStreamWriter(out, encoding); 156 | } 157 | 158 | /** 159 | * Create a new Writer with specified encoding. 160 | * 161 | * @param file not null file. 162 | * @param encoding not null supported encoding. 163 | * @return a writer instance for the output file using the given encoding. 164 | * @throws IOException if any. 165 | * @see Supported encodings 166 | */ 167 | public static Writer newWriter(File file, String encoding) throws IOException { 168 | return newWriter(Files.newOutputStream(file.toPath()), encoding); 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/cli/AbstractStreamHandler.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.cli; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** 20 | * @author Kristian Rosenvold 21 | */ 22 | public class AbstractStreamHandler extends Thread { 23 | private boolean done; 24 | 25 | private volatile boolean disabled; 26 | 27 | public boolean isDone() { 28 | return done; 29 | } 30 | 31 | public synchronized void waitUntilDone() throws InterruptedException { 32 | while (!isDone()) { 33 | wait(); 34 | } 35 | } 36 | 37 | protected boolean isDisabled() { 38 | return disabled; 39 | } 40 | 41 | public void disable() { 42 | disabled = true; 43 | } 44 | 45 | public void setDone() { 46 | done = true; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/cli/Arg.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.cli; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.io.File; 20 | 21 | public interface Arg { 22 | void setValue(String value); 23 | 24 | void setLine(String line); 25 | 26 | void setFile(File value); 27 | 28 | String[] getParts(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/cli/CommandLineCallable.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.cli; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.util.concurrent.Callable; 20 | 21 | /** 22 | * Callable wrapper that exposes the proper exception type to the client. 23 | * 24 | * @author Kristian Rosenvold 25 | */ 26 | public interface CommandLineCallable extends Callable { 27 | @Override 28 | Integer call() throws CommandLineException; 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/cli/CommandLineException.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.cli; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** 20 | * @author Trygve Laugstøl 21 | * 22 | */ 23 | public class CommandLineException extends Exception { 24 | public CommandLineException(String message) { 25 | super(message); 26 | } 27 | 28 | public CommandLineException(String message, Throwable cause) { 29 | super(message, cause); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/cli/CommandLineTimeOutException.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.cli; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | /** 23 | * @author olamy 24 | * @since 1.5.9 25 | * 26 | */ 27 | public class CommandLineTimeOutException extends CommandLineException { 28 | 29 | public CommandLineTimeOutException(String message) { 30 | super(message); 31 | } 32 | 33 | public CommandLineTimeOutException(String message, Throwable cause) { 34 | super(message, cause); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/cli/DefaultConsumer.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.cli; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.io.IOException; 20 | 21 | /** 22 | * @author Emmanuel Venisse 23 | * 24 | */ 25 | public class DefaultConsumer implements StreamConsumer { 26 | 27 | @Override 28 | public void consumeLine(String line) throws IOException { 29 | System.out.println(line); 30 | 31 | if (System.out.checkError()) { 32 | throw new IOException(String.format("Failure printing line '%s' to stdout.", line)); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizer.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.cli; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.util.StringTokenizer; 20 | 21 | /** 22 | * The java.util.StringTokenizer is horribly broken. Given the string 1,,,3,,4 (, delim) It will return 1,3,4 Which is 23 | * clearly wrong - 1,EMPTY,EMPTY,3,EMPTY,4 is what it should return 24 | * 25 | * 26 | */ 27 | public final class EnhancedStringTokenizer { 28 | private StringTokenizer cst = null; 29 | 30 | String cdelim; 31 | 32 | final boolean cdelimSingleChar; 33 | 34 | final char cdelimChar; 35 | 36 | boolean creturnDelims; 37 | 38 | String lastToken = null; 39 | 40 | boolean delimLast = true; 41 | 42 | public EnhancedStringTokenizer(String str) { 43 | this(str, " \t\n\r\f", false); 44 | } 45 | 46 | public EnhancedStringTokenizer(String str, String delim) { 47 | this(str, delim, false); 48 | } 49 | 50 | public EnhancedStringTokenizer(String str, String delim, boolean returnDelims) { 51 | cst = new StringTokenizer(str, delim, true); 52 | cdelim = delim; 53 | creturnDelims = returnDelims; 54 | cdelimSingleChar = (delim.length() == 1); 55 | cdelimChar = delim.charAt(0); 56 | } 57 | 58 | public boolean hasMoreTokens() { 59 | return cst.hasMoreTokens(); 60 | } 61 | 62 | private String internalNextToken() { 63 | if (lastToken != null) { 64 | String last = lastToken; 65 | lastToken = null; 66 | return last; 67 | } 68 | 69 | String token = cst.nextToken(); 70 | if (isDelim(token)) { 71 | if (delimLast) { 72 | lastToken = token; 73 | return ""; 74 | } else { 75 | delimLast = true; 76 | return token; 77 | } 78 | } else { 79 | delimLast = false; 80 | return token; 81 | } 82 | } 83 | 84 | public String nextToken() { 85 | String token = internalNextToken(); 86 | if (creturnDelims) { 87 | return token; 88 | } 89 | if (isDelim(token)) { 90 | return hasMoreTokens() ? internalNextToken() : ""; 91 | } else { 92 | return token; 93 | } 94 | } 95 | 96 | private boolean isDelim(String str) { 97 | if (str.length() == 1) { 98 | char ch = str.charAt(0); 99 | if (cdelimSingleChar) { 100 | if (cdelimChar == ch) { 101 | return true; 102 | } 103 | } else { 104 | if (cdelim.indexOf(ch) >= 0) { 105 | return true; 106 | } 107 | } 108 | } 109 | return false; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/cli/ShutdownHookUtils.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.cli; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.security.AccessControlException; 20 | 21 | /** 22 | * A shutdown hook that does not throw any exceptions upon container startup/shutdown or security manager restrictions. 23 | * Incorrect usage of the hook itself may still throw an exception. 24 | * 25 | * @author Kristian Rosenvold 26 | */ 27 | class ShutdownHookUtils { 28 | 29 | public static void addShutDownHook(Thread hook) { 30 | try { 31 | Runtime.getRuntime().addShutdownHook(hook); 32 | } catch (IllegalStateException ignore) { 33 | } catch (AccessControlException ignore) { 34 | } 35 | } 36 | 37 | public static void removeShutdownHook(Thread hook) { 38 | try { 39 | Runtime.getRuntime().removeShutdownHook(hook); 40 | } catch (IllegalStateException ignore) { 41 | } catch (AccessControlException ignore) { 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/cli/StreamConsumer.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.cli; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /******************************************************************************** 20 | * CruiseControl, a Continuous Integration Toolkit 21 | * Copyright (c) 2003, ThoughtWorks, Inc. 22 | * 651 W Washington Ave. Suite 500 23 | * Chicago, IL 60661 USA 24 | * All rights reserved. 25 | * 26 | * Redistribution and use in source and binary forms, with or without 27 | * modification, are permitted provided that the following conditions 28 | * are met: 29 | * 30 | * + Redistributions of source code must retain the above copyright 31 | * notice, this list of conditions and the following disclaimer. 32 | * 33 | * + Redistributions in binary form must reproduce the above 34 | * copyright notice, this list of conditions and the following 35 | * disclaimer in the documentation and/or other materials provided 36 | * with the distribution. 37 | * 38 | * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the 39 | * names of its contributors may be used to endorse or promote 40 | * products derived from this software without specific prior 41 | * written permission. 42 | * 43 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 44 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 45 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 46 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 47 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 48 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 49 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 50 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 51 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 52 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 53 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 54 | ********************************************************************************/ 55 | import java.io.IOException; 56 | 57 | /** 58 | * Works in concert with the StreamPumper class to allow implementations to gain access to the lines being "Pumped". 59 | * Please note that implementations of this interface can be expected to be called from arbitrary threads and must 60 | * therefore be threadsafe. 61 | * 62 | * @author Florin Vancea 63 | * @author Paul Julius 64 | * 65 | */ 66 | public interface StreamConsumer { 67 | /** 68 | * Called when the StreamPumper pumps a line from the Stream. 69 | * 70 | * @param line The line to be consumed. 71 | * @throws IOException if consuming {@code line} fails. 72 | */ 73 | public void consumeLine(String line) throws IOException; 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/cli/StreamFeeder.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.cli; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | import java.io.OutputStream; 22 | 23 | /** 24 | * Read from an InputStream and write the output to an OutputStream. 25 | * 26 | * @author Trygve Laugstøl 27 | * 28 | */ 29 | public class StreamFeeder extends AbstractStreamHandler { 30 | 31 | private InputStream input; 32 | 33 | private OutputStream output; 34 | 35 | private volatile Throwable exception = null; 36 | 37 | /** 38 | * Create a new StreamFeeder 39 | * 40 | * @param input Stream to read from 41 | * @param output Stream to write to 42 | */ 43 | public StreamFeeder(InputStream input, OutputStream output) { 44 | super(); 45 | this.input = input; 46 | this.output = output; 47 | } 48 | 49 | @Override 50 | public void run() { 51 | try { 52 | feed(); 53 | } catch (Throwable ex) { 54 | if (exception == null) { 55 | exception = ex; 56 | } 57 | } finally { 58 | close(); 59 | 60 | synchronized (this) { 61 | setDone(); 62 | 63 | this.notifyAll(); 64 | } 65 | } 66 | } 67 | 68 | public void close() { 69 | if (input != null) { 70 | synchronized (input) { 71 | try { 72 | input.close(); 73 | } catch (IOException ex) { 74 | if (exception == null) { 75 | exception = ex; 76 | } 77 | } 78 | 79 | input = null; 80 | } 81 | } 82 | 83 | if (output != null) { 84 | synchronized (output) { 85 | try { 86 | output.close(); 87 | } catch (IOException ex) { 88 | if (exception == null) { 89 | exception = ex; 90 | } 91 | } 92 | 93 | output = null; 94 | } 95 | } 96 | } 97 | 98 | /** 99 | * @since 3.1.0 100 | * @return the Exception 101 | */ 102 | public Throwable getException() { 103 | return exception; 104 | } 105 | 106 | private void feed() throws IOException { 107 | boolean flush = false; 108 | int data = input.read(); 109 | 110 | while (!isDone() && data != -1) { 111 | synchronized (output) { 112 | if (!isDisabled()) { 113 | output.write(data); 114 | flush = true; 115 | } 116 | 117 | data = input.read(); 118 | } 119 | } 120 | 121 | if (flush) { 122 | output.flush(); 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/cli/WriterStreamConsumer.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.cli; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.io.PrintWriter; 20 | import java.io.Writer; 21 | 22 | /** 23 | * @author Jason van Zyl 24 | * 25 | */ 26 | public class WriterStreamConsumer implements StreamConsumer { 27 | private PrintWriter writer; 28 | 29 | public WriterStreamConsumer(Writer writer) { 30 | this.writer = new PrintWriter(writer); 31 | } 32 | 33 | @Override 34 | public void consumeLine(String line) { 35 | writer.println(line); 36 | 37 | writer.flush(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/cli/shell/BourneShell.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.cli.shell; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | import org.codehaus.plexus.util.Os; 23 | 24 | /** 25 | * @author Jason van Zyl 26 | * 27 | */ 28 | public class BourneShell extends Shell { 29 | 30 | public BourneShell() { 31 | this(false); 32 | } 33 | 34 | public BourneShell(boolean isLoginShell) { 35 | setUnconditionalQuoting(true); 36 | setShellCommand("/bin/sh"); 37 | setArgumentQuoteDelimiter('\''); 38 | setExecutableQuoteDelimiter('\''); 39 | setSingleQuotedArgumentEscaped(true); 40 | setSingleQuotedExecutableEscaped(false); 41 | setQuotedExecutableEnabled(true); 42 | setArgumentEscapePattern("'\\%s'"); 43 | 44 | if (isLoginShell) { 45 | addShellArg("-l"); 46 | } 47 | } 48 | 49 | /** {@inheritDoc} */ 50 | @Override 51 | public String getExecutable() { 52 | if (Os.isFamily(Os.FAMILY_WINDOWS)) { 53 | return super.getExecutable(); 54 | } 55 | 56 | return quoteOneItem(super.getOriginalExecutable(), true); 57 | } 58 | 59 | @Override 60 | public List getShellArgsList() { 61 | List shellArgs = new ArrayList(); 62 | List existingShellArgs = super.getShellArgsList(); 63 | 64 | if ((existingShellArgs != null) && !existingShellArgs.isEmpty()) { 65 | shellArgs.addAll(existingShellArgs); 66 | } 67 | 68 | shellArgs.add("-c"); 69 | 70 | return shellArgs; 71 | } 72 | 73 | @Override 74 | public String[] getShellArgs() { 75 | String[] shellArgs = super.getShellArgs(); 76 | if (shellArgs == null) { 77 | shellArgs = new String[0]; 78 | } 79 | 80 | if ((shellArgs.length > 0) && !shellArgs[shellArgs.length - 1].equals("-c")) { 81 | String[] newArgs = new String[shellArgs.length + 1]; 82 | 83 | System.arraycopy(shellArgs, 0, newArgs, 0, shellArgs.length); 84 | newArgs[shellArgs.length] = "-c"; 85 | 86 | shellArgs = newArgs; 87 | } 88 | 89 | return shellArgs; 90 | } 91 | 92 | @Override 93 | protected String getExecutionPreamble() { 94 | if (getWorkingDirectoryAsString() == null) { 95 | return null; 96 | } 97 | 98 | String dir = getWorkingDirectoryAsString(); 99 | StringBuilder sb = new StringBuilder(); 100 | sb.append("cd "); 101 | 102 | sb.append(quoteOneItem(dir, false)); 103 | sb.append(" && "); 104 | 105 | return sb.toString(); 106 | } 107 | 108 | /** 109 | *

110 | * Unify quotes in a path for the Bourne Shell. 111 | *

112 | * 113 | *
114 |      * BourneShell.quoteOneItem(null)                       = null
115 |      * BourneShell.quoteOneItem("")                         = ''
116 |      * BourneShell.quoteOneItem("/test/quotedpath'abc")     = '/test/quotedpath'"'"'abc'
117 |      * BourneShell.quoteOneItem("/test/quoted path'abc")    = '/test/quoted pat'"'"'habc'
118 |      * BourneShell.quoteOneItem("/test/quotedpath\"abc")    = '/test/quotedpath"abc'
119 |      * BourneShell.quoteOneItem("/test/quoted path\"abc")   = '/test/quoted path"abc'
120 |      * BourneShell.quoteOneItem("/test/quotedpath\"'abc")   = '/test/quotedpath"'"'"'abc'
121 |      * BourneShell.quoteOneItem("/test/quoted path\"'abc")  = '/test/quoted path"'"'"'abc'
122 |      * 
123 | * 124 | * @param path not null path. 125 | * @return the path unified correctly for the Bourne shell. 126 | */ 127 | @Override 128 | protected String quoteOneItem(String path, boolean isExecutable) { 129 | if (path == null) { 130 | return null; 131 | } 132 | 133 | StringBuilder sb = new StringBuilder(); 134 | sb.append("'"); 135 | sb.append(path.replace("'", "'\"'\"'")); 136 | sb.append("'"); 137 | 138 | return sb.toString(); 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/cli/shell/CmdShell.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.cli.shell; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.util.Arrays; 20 | import java.util.List; 21 | 22 | /** 23 | *

24 | * Implementation to call the CMD Shell present on Windows NT, 2000 and XP 25 | *

26 | * 27 | * @author Carlos Sanchez 28 | * @since 1.2 29 | * 30 | */ 31 | public class CmdShell extends Shell { 32 | public CmdShell() { 33 | setShellCommand("cmd.exe"); 34 | setQuotedExecutableEnabled(true); 35 | setShellArgs(new String[] {"/X", "/D", "/C"}); 36 | } 37 | 38 | /** 39 | *

40 | * Specific implementation that quotes all the command line. 41 | *

42 | *

43 | * Workaround for http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6468220 44 | *

45 | *

46 | * From cmd.exe /? output: 47 | *

48 | * 49 | *
50 |      *      If /C or /K is specified, then the remainder of the command line after
51 |      *      the switch is processed as a command line, where the following logic is
52 |      *      used to process quote (") characters:
53 |      *
54 |      *      1.  If all of the following conditions are met, then quote characters
55 |      *      on the command line are preserved:
56 |      *
57 |      *      - no /S switch
58 |      *      - exactly two quote characters
59 |      *      - no special characters between the two quote characters,
60 |      *      where special is one of: &<>()@ˆ|
61 |      *      - there are one or more whitespace characters between the
62 |      *      the two quote characters
63 |      *      - the string between the two quote characters is the name
64 |      *      of an executable file.
65 |      *
66 |      *      2.  Otherwise, old behavior is to see if the first character is
67 |      *      a quote character and if so, strip the leading character and
68 |      *      remove the last quote character on the command line, preserving
69 |      *      any text after the last quote character.
70 |      * 
71 | *

72 | * Always quoting the entire command line, regardless of these conditions appears to make Windows processes invoke 73 | * successfully. 74 | *

75 | */ 76 | @Override 77 | public List getCommandLine(String executable, String[] arguments) { 78 | StringBuilder sb = new StringBuilder(); 79 | sb.append("\""); 80 | sb.append(super.getCommandLine(executable, arguments).get(0)); 81 | sb.append("\""); 82 | 83 | return Arrays.asList(new String[] {sb.toString()}); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/cli/shell/CommandShell.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.cli.shell; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** 20 | *

21 | * Implementation to call the Command.com Shell present on Windows 95, 98 and Me 22 | *

23 | * 24 | * @author Carlos Sanchez 25 | * @since 1.2 26 | * 27 | */ 28 | public class CommandShell extends Shell { 29 | public CommandShell() { 30 | setShellCommand("command.com"); 31 | setShellArgs(new String[] {"/C"}); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/dag/CycleDetectedException.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.dag; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.util.Iterator; 20 | import java.util.List; 21 | 22 | public class CycleDetectedException extends Exception { 23 | private List cycle; 24 | 25 | public CycleDetectedException(final String message, final List cycle) { 26 | super(message); 27 | 28 | this.cycle = cycle; 29 | } 30 | 31 | public List getCycle() { 32 | return cycle; 33 | } 34 | 35 | public String cycleToString() { 36 | final StringBuilder buffer = new StringBuilder(); 37 | 38 | for (Iterator iterator = cycle.iterator(); iterator.hasNext(); ) { 39 | buffer.append(iterator.next()); 40 | 41 | if (iterator.hasNext()) { 42 | buffer.append(" --> "); 43 | } 44 | } 45 | return buffer.toString(); 46 | } 47 | 48 | @Override 49 | public String getMessage() { 50 | return super.getMessage() + " " + cycleToString(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/dag/CycleDetector.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.dag; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.util.Collections; 20 | import java.util.HashMap; 21 | import java.util.LinkedList; 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | /** 26 | * @author Michal Maczka 27 | * 28 | */ 29 | public class CycleDetector { 30 | 31 | private static final Integer NOT_VISITED = 0; 32 | 33 | private static final Integer VISITING = 1; 34 | 35 | private static final Integer VISITED = 2; 36 | 37 | public static List hasCycle(final DAG graph) { 38 | final List vertices = graph.getVertices(); 39 | 40 | final Map vertexStateMap = new HashMap<>(); 41 | 42 | List retValue = null; 43 | 44 | for (Vertex vertex : vertices) { 45 | if (isNotVisited(vertex, vertexStateMap)) { 46 | retValue = introducesCycle(vertex, vertexStateMap); 47 | 48 | if (retValue != null) { 49 | break; 50 | } 51 | } 52 | } 53 | 54 | return retValue; 55 | } 56 | 57 | /** 58 | * This method will be called when an edge leading to given vertex was added and we want to check if introduction of 59 | * this edge has not resulted in apparition of cycle in the graph 60 | * 61 | * @param vertex the vertex 62 | * @param vertexStateMap the vertex Map 63 | * @return the found cycle 64 | */ 65 | public static List introducesCycle(final Vertex vertex, final Map vertexStateMap) { 66 | final LinkedList cycleStack = new LinkedList<>(); 67 | 68 | final boolean hasCycle = dfsVisit(vertex, cycleStack, vertexStateMap); 69 | 70 | if (hasCycle) { 71 | // we have a situation like: [b, a, c, d, b, f, g, h]. 72 | // Label of Vertex which introduced the cycle is at the first position in the list 73 | // We have to find second occurrence of this label and use its position in the list 74 | // for getting the sublist of vertex labels of cycle participants 75 | // 76 | // So in our case we are searching for [b, a, c, d, b] 77 | final String label = cycleStack.getFirst(); 78 | 79 | final int pos = cycleStack.lastIndexOf(label); 80 | 81 | final List cycle = cycleStack.subList(0, pos + 1); 82 | 83 | Collections.reverse(cycle); 84 | 85 | return cycle; 86 | } 87 | 88 | return null; 89 | } 90 | 91 | public static List introducesCycle(final Vertex vertex) { 92 | final Map vertexStateMap = new HashMap<>(); 93 | 94 | return introducesCycle(vertex, vertexStateMap); 95 | } 96 | 97 | private static boolean isNotVisited(final Vertex vertex, final Map vertexStateMap) { 98 | final Integer state = vertexStateMap.get(vertex); 99 | 100 | return (state == null) || NOT_VISITED.equals(state); 101 | } 102 | 103 | private static boolean isVisiting(final Vertex vertex, final Map vertexStateMap) { 104 | final Integer state = vertexStateMap.get(vertex); 105 | 106 | return VISITING.equals(state); 107 | } 108 | 109 | private static boolean dfsVisit( 110 | final Vertex vertex, final LinkedList cycle, final Map vertexStateMap) { 111 | cycle.addFirst(vertex.getLabel()); 112 | 113 | vertexStateMap.put(vertex, VISITING); 114 | 115 | for (Vertex v : vertex.getChildren()) { 116 | if (isNotVisited(v, vertexStateMap)) { 117 | final boolean hasCycle = dfsVisit(v, cycle, vertexStateMap); 118 | 119 | if (hasCycle) { 120 | return true; 121 | } 122 | } else if (isVisiting(v, vertexStateMap)) { 123 | cycle.addFirst(v.getLabel()); 124 | 125 | return true; 126 | } 127 | } 128 | vertexStateMap.put(vertex, VISITED); 129 | 130 | cycle.removeFirst(); 131 | 132 | return false; 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/dag/TopologicalSorter.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.dag; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.util.HashMap; 20 | import java.util.LinkedList; 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | /** 25 | * @author Michal Maczka 26 | * 27 | */ 28 | public class TopologicalSorter { 29 | 30 | private static final Integer NOT_VISITED = 0; 31 | 32 | private static final Integer VISITING = 1; 33 | 34 | private static final Integer VISITED = 2; 35 | 36 | /** 37 | * @param graph the graph 38 | * @return List of String (vertex labels) 39 | */ 40 | public static List sort(final DAG graph) { 41 | return dfs(graph); 42 | } 43 | 44 | public static List sort(final Vertex vertex) { 45 | // we need to use addFirst method so we will use LinkedList explicitly 46 | final List retValue = new LinkedList<>(); 47 | 48 | dfsVisit(vertex, new HashMap(), retValue); 49 | 50 | return retValue; 51 | } 52 | 53 | private static List dfs(final DAG graph) { 54 | // we need to use addFirst method so we will use LinkedList explicitly 55 | final List retValue = new LinkedList<>(); 56 | final Map vertexStateMap = new HashMap<>(); 57 | 58 | for (Vertex vertex : graph.getVertices()) { 59 | if (isNotVisited(vertex, vertexStateMap)) { 60 | dfsVisit(vertex, vertexStateMap, retValue); 61 | } 62 | } 63 | 64 | return retValue; 65 | } 66 | 67 | private static boolean isNotVisited(final Vertex vertex, final Map vertexStateMap) { 68 | final Integer state = vertexStateMap.get(vertex); 69 | 70 | return (state == null) || NOT_VISITED.equals(state); 71 | } 72 | 73 | private static void dfsVisit( 74 | final Vertex vertex, final Map vertexStateMap, final List list) { 75 | vertexStateMap.put(vertex, VISITING); 76 | 77 | for (Vertex v : vertex.getChildren()) { 78 | if (isNotVisited(v, vertexStateMap)) { 79 | dfsVisit(v, vertexStateMap, list); 80 | } 81 | } 82 | 83 | vertexStateMap.put(vertex, VISITED); 84 | 85 | list.add(vertex.getLabel()); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/dag/Vertex.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.dag; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.io.Serializable; 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | /** 24 | * @author Michal Maczka 25 | * 26 | */ 27 | public class Vertex implements Cloneable, Serializable { 28 | // ------------------------------------------------------------ 29 | // Fields 30 | // ------------------------------------------------------------ 31 | private String label = null; 32 | 33 | List children = new ArrayList<>(); 34 | 35 | List parents = new ArrayList<>(); 36 | 37 | // ------------------------------------------------------------ 38 | // Constructors 39 | // ------------------------------------------------------------ 40 | 41 | public Vertex(final String label) { 42 | this.label = label; 43 | } 44 | 45 | // ------------------------------------------------------------ 46 | // Accessors 47 | // ------------------------------------------------------------ 48 | 49 | public String getLabel() { 50 | return label; 51 | } 52 | 53 | public void addEdgeTo(final Vertex vertex) { 54 | children.add(vertex); 55 | } 56 | 57 | public void removeEdgeTo(final Vertex vertex) { 58 | children.remove(vertex); 59 | } 60 | 61 | public void addEdgeFrom(final Vertex vertex) { 62 | parents.add(vertex); 63 | } 64 | 65 | public void removeEdgeFrom(final Vertex vertex) { 66 | parents.remove(vertex); 67 | } 68 | 69 | public List getChildren() { 70 | return children; 71 | } 72 | 73 | /** 74 | * Get the labels used by the most direct children. 75 | * 76 | * @return the labels used by the most direct children. 77 | */ 78 | public List getChildLabels() { 79 | final List retValue = new ArrayList<>(children.size()); 80 | 81 | for (Vertex vertex : children) { 82 | retValue.add(vertex.getLabel()); 83 | } 84 | return retValue; 85 | } 86 | 87 | /** 88 | * Get the list the most direct ancestors (parents). 89 | * 90 | * @return list of parents 91 | */ 92 | public List getParents() { 93 | return parents; 94 | } 95 | 96 | /** 97 | * Get the labels used by the most direct ancestors (parents). 98 | * 99 | * @return the labels used parents 100 | */ 101 | public List getParentLabels() { 102 | final List retValue = new ArrayList<>(parents.size()); 103 | 104 | for (Vertex vertex : parents) { 105 | retValue.add(vertex.getLabel()); 106 | } 107 | return retValue; 108 | } 109 | 110 | /** 111 | * Indicates if given vertex has no child 112 | * 113 | * @return true if this vertex has no child, false otherwise 114 | */ 115 | public boolean isLeaf() { 116 | return children.size() == 0; 117 | } 118 | 119 | /** 120 | * Indicates if given vertex has no parent 121 | * 122 | * @return true if this vertex has no parent, false otherwise 123 | */ 124 | public boolean isRoot() { 125 | return parents.size() == 0; 126 | } 127 | 128 | /** 129 | * Indicates if there is at least one edee leading to or from given vertex 130 | * 131 | * @return true if this vertex is connected with other vertex,false otherwise 132 | */ 133 | public boolean isConnected() { 134 | return isRoot() || isLeaf(); 135 | } 136 | 137 | @Override 138 | public Object clone() throws CloneNotSupportedException { 139 | // this is what's failing.. 140 | final Object retValue = super.clone(); 141 | 142 | return retValue; 143 | } 144 | 145 | @Override 146 | public String toString() { 147 | return "Vertex{" + "label='" + label + "'" + "}"; 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/io/CachingOutputStream.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.io; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.io.File; 20 | import java.io.IOException; 21 | import java.io.OutputStream; 22 | import java.nio.Buffer; 23 | import java.nio.ByteBuffer; 24 | import java.nio.channels.FileChannel; 25 | import java.nio.file.Path; 26 | import java.nio.file.StandardOpenOption; 27 | import java.util.Objects; 28 | 29 | /** 30 | * Caching OutputStream to avoid overwriting a file with 31 | * the same content. 32 | */ 33 | public class CachingOutputStream extends OutputStream { 34 | private final Path path; 35 | private FileChannel channel; 36 | private ByteBuffer readBuffer; 37 | private ByteBuffer writeBuffer; 38 | private boolean modified; 39 | 40 | public CachingOutputStream(File path) throws IOException { 41 | this(Objects.requireNonNull(path).toPath()); 42 | } 43 | 44 | public CachingOutputStream(Path path) throws IOException { 45 | this(path, 32 * 1024); 46 | } 47 | 48 | public CachingOutputStream(Path path, int bufferSize) throws IOException { 49 | this.path = Objects.requireNonNull(path); 50 | this.channel = 51 | FileChannel.open(path, StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.CREATE); 52 | this.readBuffer = ByteBuffer.allocate(bufferSize); 53 | this.writeBuffer = ByteBuffer.allocate(bufferSize); 54 | } 55 | 56 | @Override 57 | public void write(int b) throws IOException { 58 | if (writeBuffer.remaining() < 1) { 59 | ((Buffer) writeBuffer).flip(); 60 | flushBuffer(writeBuffer); 61 | ((Buffer) writeBuffer).clear(); 62 | } 63 | writeBuffer.put((byte) b); 64 | } 65 | 66 | @Override 67 | public void write(byte[] b) throws IOException { 68 | write(b, 0, b.length); 69 | } 70 | 71 | @Override 72 | public void write(byte[] b, int off, int len) throws IOException { 73 | if (writeBuffer.remaining() < len) { 74 | ((Buffer) writeBuffer).flip(); 75 | flushBuffer(writeBuffer); 76 | ((Buffer) writeBuffer).clear(); 77 | } 78 | int capacity = writeBuffer.capacity(); 79 | while (len >= capacity) { 80 | flushBuffer(ByteBuffer.wrap(b, off, capacity)); 81 | off += capacity; 82 | len -= capacity; 83 | } 84 | if (len > 0) { 85 | writeBuffer.put(b, off, len); 86 | } 87 | } 88 | 89 | @Override 90 | public void flush() throws IOException { 91 | ((Buffer) writeBuffer).flip(); 92 | flushBuffer(writeBuffer); 93 | ((Buffer) writeBuffer).clear(); 94 | super.flush(); 95 | } 96 | 97 | private void flushBuffer(ByteBuffer writeBuffer) throws IOException { 98 | if (modified) { 99 | channel.write(writeBuffer); 100 | } else { 101 | int len = writeBuffer.remaining(); 102 | ByteBuffer readBuffer; 103 | if (this.readBuffer.capacity() >= len) { 104 | readBuffer = this.readBuffer; 105 | ((Buffer) readBuffer).clear(); 106 | readBuffer.limit(len); 107 | } else { 108 | readBuffer = ByteBuffer.allocate(len); 109 | } 110 | while (len > 0) { 111 | int read = channel.read(readBuffer); 112 | if (read <= 0) { 113 | modified = true; 114 | channel.position(channel.position() - readBuffer.position()); 115 | channel.write(writeBuffer); 116 | return; 117 | } 118 | len -= read; 119 | } 120 | ((Buffer) readBuffer).flip(); 121 | if (readBuffer.compareTo(writeBuffer) != 0) { 122 | modified = true; 123 | channel.position(channel.position() - readBuffer.remaining()); 124 | channel.write(writeBuffer); 125 | } 126 | } 127 | } 128 | 129 | @Override 130 | public void close() throws IOException { 131 | if (channel.isOpen()) { 132 | flush(); 133 | long position = channel.position(); 134 | if (position != channel.size()) { 135 | modified = true; 136 | channel.truncate(position); 137 | } 138 | channel.close(); 139 | } 140 | } 141 | 142 | public boolean isModified() { 143 | return modified; 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/io/CachingWriter.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.io; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.io.File; 20 | import java.io.IOException; 21 | import java.io.OutputStreamWriter; 22 | import java.nio.charset.Charset; 23 | import java.nio.file.Path; 24 | import java.util.Objects; 25 | 26 | /** 27 | * Caching Writer to avoid overwriting a file with 28 | * the same content. 29 | */ 30 | public class CachingWriter extends OutputStreamWriter { 31 | private final CachingOutputStream cos; 32 | 33 | public CachingWriter(File path, Charset charset) throws IOException { 34 | this(Objects.requireNonNull(path).toPath(), charset); 35 | } 36 | 37 | public CachingWriter(Path path, Charset charset) throws IOException { 38 | this(path, charset, 32 * 1024); 39 | } 40 | 41 | public CachingWriter(Path path, Charset charset, int bufferSize) throws IOException { 42 | this(new CachingOutputStream(path, bufferSize), charset); 43 | } 44 | 45 | private CachingWriter(CachingOutputStream outputStream, Charset charset) throws IOException { 46 | super(outputStream, charset); 47 | this.cos = outputStream; 48 | } 49 | 50 | public boolean isModified() { 51 | return cos.isModified(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/io/InputStreamFacade.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.io; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | 22 | /** 23 | * Interface of a wrapper for input streams. This facade is used by methods, which are being implemented for files, 24 | * URL's, or input streams. 25 | */ 26 | public interface InputStreamFacade { 27 | /** 28 | * The caller must assume, that this method may be invoked only once. 29 | * @return Retrieves the actual {@link InputStream}. 30 | * @throws IOException if io issue 31 | */ 32 | InputStream getInputStream() throws IOException; 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/io/RawInputStreamFacade.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.io; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | 22 | /** 23 | * Implementation of {@link InputStreamFacade} for raw input streams. 24 | */ 25 | @SuppressWarnings({"UnusedDeclaration"}) 26 | public class RawInputStreamFacade implements InputStreamFacade { 27 | final InputStream stream; 28 | 29 | public RawInputStreamFacade(InputStream stream) { 30 | this.stream = stream; 31 | } 32 | 33 | @Override 34 | public InputStream getInputStream() throws IOException { 35 | return stream; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/io/URLInputStreamFacade.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.io; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | import java.net.URL; 22 | 23 | /** 24 | * Implementation of {@link InputStreamFacade} for URL's. 25 | */ 26 | public class URLInputStreamFacade implements InputStreamFacade { 27 | private final URL url; 28 | 29 | public URLInputStreamFacade(URL url) { 30 | this.url = url; 31 | } 32 | 33 | @Override 34 | public InputStream getInputStream() throws IOException { 35 | return url.openStream(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/plexus/util/reflection/ReflectorException.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.reflection; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** 20 | * Exception indicating that an error has occurred while instantiating a class with the Reflector class. This exception 21 | * is meant to put a more user-friendly face on the myriad other exceptions throws during reflective object creation. 22 | * 23 | * @author John Casey 24 | */ 25 | public class ReflectorException extends Exception { 26 | @SuppressWarnings({"UnusedDeclaration"}) 27 | public ReflectorException() {} 28 | 29 | /** 30 | * Create a new ReflectorException with the specified message. 31 | * 32 | * @param msg The message. 33 | */ 34 | public ReflectorException(String msg) { 35 | super(msg); 36 | } 37 | 38 | /** 39 | * Create a new ReflectorException with the specified root cause. 40 | * 41 | * @param root The root cause. 42 | */ 43 | public ReflectorException(Throwable root) { 44 | super(root); 45 | } 46 | 47 | /** 48 | * Create a new ReflectorException with the specified message and root cause. 49 | * 50 | * @param msg The message. 51 | * @param root The root cause. 52 | */ 53 | public ReflectorException(String msg, Throwable root) { 54 | super(msg, root); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java10/org/codehaus/plexus/util/BaseIOUtil.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.io.OutputStream; 6 | import java.io.Reader; 7 | import java.io.Writer; 8 | 9 | /** 10 | * Implementation specific to Java SE 10 version. 11 | */ 12 | abstract class BaseIOUtil 13 | { 14 | static void copy( final InputStream input, final OutputStream output ) 15 | throws IOException 16 | { 17 | input.transferTo( output ); 18 | } 19 | 20 | static void copy( final Reader input, final Writer output ) 21 | throws IOException 22 | { 23 | input.transferTo( output ); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java11/org/codehaus/plexus/util/BaseFileUtils.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | import java.io.IOException; 4 | import java.nio.charset.Charset; 5 | import java.nio.file.Files; 6 | import java.nio.file.OpenOption; 7 | import java.nio.file.Path; 8 | import java.nio.file.StandardOpenOption; 9 | 10 | /** 11 | * Implementation specific to Java SE 11 version. 12 | */ 13 | abstract class BaseFileUtils 14 | { 15 | static String fileRead( Path path, String encoding ) throws IOException 16 | { 17 | return encoding != null ? Files.readString( path, Charset.forName( encoding ) ) : Files.readString( path ); 18 | } 19 | 20 | static void fileWrite( Path path, String encoding, String data, OpenOption... openOptions ) throws IOException 21 | { 22 | if ( encoding != null ) 23 | { 24 | Files.writeString( path, data, Charset.forName( encoding ), openOptions ); 25 | } 26 | else 27 | { 28 | Files.writeString( path, data, openOptions ); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java9/org/codehaus/plexus/util/BaseIOUtil.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.io.OutputStream; 6 | import java.io.Reader; 7 | import java.io.Writer; 8 | 9 | /** 10 | * Implementation specific to Java SE 9 version. 11 | */ 12 | abstract class BaseIOUtil 13 | { 14 | private static final int DEFAULT_BUFFER_SIZE = 1024 * 16; 15 | 16 | static void copy( final InputStream input, final OutputStream output ) 17 | throws IOException 18 | { 19 | input.transferTo( output ); 20 | } 21 | 22 | static void copy( final Reader input, final Writer output ) 23 | throws IOException 24 | { 25 | IOUtil.copy( input, output, DEFAULT_BUFFER_SIZE ); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/javadoc/org/codehaus/plexus/util/cli/package.html: -------------------------------------------------------------------------------- 1 | 2 | Command-line utilities. 3 | -------------------------------------------------------------------------------- /src/main/javadoc/org/codehaus/plexus/util/cli/shell/package.html: -------------------------------------------------------------------------------- 1 | 2 | Shell utilities. 3 | -------------------------------------------------------------------------------- /src/main/javadoc/org/codehaus/plexus/util/dag/package.html: -------------------------------------------------------------------------------- 1 | 2 | Directed Acyclic Graph utilities. 3 | -------------------------------------------------------------------------------- /src/main/javadoc/org/codehaus/plexus/util/introspection/package.html: -------------------------------------------------------------------------------- 1 | 2 | Introspection utilities. 3 | -------------------------------------------------------------------------------- /src/main/javadoc/org/codehaus/plexus/util/io/package.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Facades to create {@code InputStream}s representing various kinds of 24 | data sources, identically. 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/main/javadoc/org/codehaus/plexus/util/package.html: -------------------------------------------------------------------------------- 1 | 2 | Miscellaneous utilities, mainly dealing with I/O, strings, and filesystems. 3 | 4 | -------------------------------------------------------------------------------- /src/main/javadoc/org/codehaus/plexus/util/reflection/package.html: -------------------------------------------------------------------------------- 1 | 2 | Reflection utilities. 3 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/NOTICE: -------------------------------------------------------------------------------- 1 | This product includes software developed by the Indiana University 2 | Extreme! Lab (http://www.extreme.indiana.edu/). 3 | 4 | This product includes software developed by 5 | The Apache Software Foundation (http://www.apache.org/). 6 | 7 | This product includes software developed by 8 | ThoughtWorks (http://www.thoughtworks.com). 9 | 10 | This product includes software developed by 11 | javolution (http://javolution.org/). 12 | 13 | This product includes software developed by 14 | Rome (https://rome.dev.java.net/). -------------------------------------------------------------------------------- /src/main/resources/licenses/extreme.indiana.edu.license.TXT: -------------------------------------------------------------------------------- 1 | Indiana University Extreme! Lab Software License 2 | 3 | Version 1.1.1 4 | 5 | Copyright (c) 2002 Extreme! Lab, Indiana University. All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in 16 | the documentation and/or other materials provided with the distribution. 17 | 18 | 3. The end-user documentation included with the redistribution, if any, 19 | must include the following acknowledgment: 20 | 21 | "This product includes software developed by the Indiana University 22 | Extreme! Lab (http://www.extreme.indiana.edu/)." 23 | 24 | Alternately, this acknowledgment may appear in the software itself, 25 | if and wherever such third-party acknowledgments normally appear. 26 | 27 | 4. The names "Indiana University" and "Indiana University Extreme! Lab" 28 | must not be used to endorse or promote products derived from this 29 | software without prior written permission. For written permission, 30 | please contact http://www.extreme.indiana.edu/. 31 | 32 | 5. Products derived from this software may not use "Indiana University" 33 | name nor may "Indiana University" appear in their name, without prior 34 | written permission of the Indiana University. 35 | 36 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 37 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 38 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 39 | IN NO EVENT SHALL THE AUTHORS, COPYRIGHT HOLDERS OR ITS CONTRIBUTORS 40 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 41 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 42 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 43 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 44 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 45 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 46 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 47 | 48 | -------------------------------------------------------------------------------- /src/main/resources/licenses/javolution.license.TXT: -------------------------------------------------------------------------------- 1 | Javolution - Java(TM) Solution for Real-Time and Embedded Systems 2 | Copyright (c) 2006, Javolution (http://javolution.org) 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /src/main/resources/licenses/thoughtworks.TXT: -------------------------------------------------------------------------------- 1 | 2 | /******************************************************************************** 3 | * CruiseControl, a Continuous Integration Toolkit 4 | * Copyright (c) 2001-2003, ThoughtWorks, Inc. 5 | * 651 W Washington Ave. Suite 500 6 | * Chicago, IL 60661 USA 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * + Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 16 | * + Redistributions in binary form must reproduce the above 17 | * copyright notice, this list of conditions and the following 18 | * disclaimer in the documentation and/or other materials provided 19 | * with the distribution. 20 | * 21 | * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the 22 | * names of its contributors may be used to endorse or promote 23 | * products derived from this software without specific prior 24 | * written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 30 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 31 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 32 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 33 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 34 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 35 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 36 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | ********************************************************************************/ -------------------------------------------------------------------------------- /src/site/markdown/index.md: -------------------------------------------------------------------------------- 1 | ## Plexus Common Utilities 2 | 3 | A collection of various utility classes to ease working with strings, files, command lines and more. 4 | 5 | Starting with version 4, XML classes (in `org.codehaus.plexus.util.xml` and `org.codehaus.plexus.util.xml.pull`) have been extracted to a separate [`plexus-xml`](../plexus-xml/) library: if you need them, just use this new artifact. 6 | 7 | `plexus-utils` 4 keeps an optional dependency on `plexus-xml` 3 to keep compatibility with the few XML-oriented methods of [`ReaderFactory`](./apidocs/org/codehaus/plexus/util/ReaderFactory.html) and [`WriterFactory`](./apidocs/org/codehaus/plexus/util/WriterFactory.html): these classes are deprecated, you should migrate as explained in javadoc. And keep `plexus-xml` to 3 if you want Maven 3 compatibility, as `plexus-xml` 4 works only in Maven 4.. 8 | -------------------------------------------------------------------------------- /src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.io.File; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import static org.junit.jupiter.api.Assertions.assertEquals; 24 | import static org.junit.jupiter.api.Assertions.assertNotNull; 25 | import static org.junit.jupiter.api.Assertions.assertTrue; 26 | 27 | /** 28 | *

DirectoryWalkerTest class.

29 | * 30 | * @author herve 31 | * @version $Id: $Id 32 | * @since 3.4.0 33 | */ 34 | class DirectoryWalkerTest { 35 | /** 36 | *

testDirectoryWalk.

37 | */ 38 | @Test 39 | void directoryWalk() { 40 | DirectoryWalker walker = new DirectoryWalker(); 41 | 42 | walker.addSCMExcludes(); 43 | 44 | walker.setBaseDir(new File("src/test/resources/directorywalker")); 45 | 46 | WalkCollector collector = new WalkCollector(); 47 | walker.addDirectoryWalkListener(collector); 48 | 49 | walker.scan(); 50 | 51 | assertEquals(1, collector.startCount, "Walk Collector / Starting Count"); 52 | assertNotNull(collector.startingDir, "Walk Collector / Starting Dir"); 53 | assertEquals(1, collector.finishCount, "Walk Collector / Finish Count"); 54 | assertEquals(4, collector.steps.size(), "Walk Collector / Steps Count"); 55 | assertTrue(collector.percentageLow >= 0, "Walk Collector / percentage low >= 0"); 56 | assertTrue(collector.percentageHigh <= 100, "Walk Collector / percentage high <= 100"); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/org/codehaus/plexus/util/MatchPatternTest.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import static org.junit.jupiter.api.Assertions.assertArrayEquals; 22 | import static org.junit.jupiter.api.Assertions.assertEquals; 23 | import static org.junit.jupiter.api.Assertions.assertFalse; 24 | import static org.junit.jupiter.api.Assertions.assertTrue; 25 | 26 | /** 27 | *

MatchPatternTest class.

28 | * 29 | * @author Kristian Rosenvold 30 | * @version $Id: $Id 31 | * @since 3.4.0 32 | */ 33 | class MatchPatternTest { 34 | 35 | /** 36 | *

testGetSource

37 | */ 38 | @Test 39 | void getSource() { 40 | MatchPattern mp = MatchPattern.fromString("ABC*"); 41 | assertEquals("ABC*", mp.getSource()); 42 | mp = MatchPattern.fromString("%ant[some/ABC*]"); 43 | assertEquals("some/ABC*", mp.getSource()); 44 | mp = MatchPattern.fromString("%regex[[ABC].*]"); 45 | assertEquals("[ABC].*", mp.getSource()); 46 | } 47 | 48 | /** 49 | *

testMatchPath.

50 | * 51 | * @throws java.lang.Exception if any. 52 | */ 53 | @Test 54 | void matchPath() throws Exception { 55 | MatchPattern mp = MatchPattern.fromString("ABC*"); 56 | assertTrue(mp.matchPath("ABCD", true)); 57 | } 58 | 59 | /** 60 | *

testMatchPatternStart.

61 | * 62 | * @see Issue #63 63 | */ 64 | @Test 65 | void matchPatternStart() { 66 | MatchPattern mp = MatchPattern.fromString("ABC*"); 67 | 68 | assertTrue(mp.matchPatternStart("ABCD", true)); 69 | assertFalse(mp.matchPatternStart("AbCD", true)); 70 | 71 | assertTrue(mp.matchPatternStart("ABCD", false)); 72 | assertTrue(mp.matchPatternStart("AbCD", false)); 73 | 74 | assertFalse(mp.matchPatternStart("XXXX", true)); 75 | assertFalse(mp.matchPatternStart("XXXX", false)); 76 | } 77 | 78 | /** 79 | *

testTokenizePathToString.

80 | */ 81 | @Test 82 | void tokenizePathToString() { 83 | String[] expected = {"hello", "world"}; 84 | String[] actual = MatchPattern.tokenizePathToString("hello/world", "/"); 85 | assertArrayEquals(expected, actual); 86 | 87 | actual = MatchPattern.tokenizePathToString("/hello/world", "/"); 88 | assertArrayEquals(expected, actual); 89 | 90 | actual = MatchPattern.tokenizePathToString("/hello/world/", "/"); 91 | assertArrayEquals(expected, actual); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.util.Arrays; 20 | import java.util.List; 21 | 22 | import org.junit.jupiter.api.Test; 23 | 24 | import static org.junit.jupiter.api.Assertions.assertEquals; 25 | import static org.junit.jupiter.api.Assertions.assertFalse; 26 | import static org.junit.jupiter.api.Assertions.assertTrue; 27 | 28 | /** 29 | *

MatchPatternsTest class.

30 | * 31 | * @author herve 32 | * @version $Id: $Id 33 | * @since 3.4.0 34 | */ 35 | class MatchPatternsTest { 36 | /** 37 | *

testGetSource

38 | */ 39 | @Test 40 | void getSources() { 41 | List expected = Arrays.asList("ABC**", "some/ABC*", "[ABC].*"); 42 | MatchPatterns from = MatchPatterns.from("ABC**", "%ant[some/ABC*]", "%regex[[ABC].*]"); 43 | List actual = from.getSources(); 44 | assertEquals(expected, actual); 45 | } 46 | 47 | /** 48 | *

testMatches.

49 | * 50 | * @throws java.lang.Exception if any. 51 | */ 52 | @Test 53 | void matches() throws Exception { 54 | MatchPatterns from = MatchPatterns.from("ABC**", "CDE**"); 55 | assertTrue(from.matches("ABCDE", true)); 56 | assertTrue(from.matches("CDEF", true)); 57 | assertFalse(from.matches("XYZ", true)); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/org/codehaus/plexus/util/OsTest.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.util.Iterator; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import static org.junit.jupiter.api.Assertions.assertEquals; 24 | import static org.junit.jupiter.api.Assertions.assertFalse; 25 | import static org.junit.jupiter.api.Assertions.assertTrue; 26 | 27 | /** 28 | * Test Case for Os 29 | * 30 | * @author herve 31 | * @version $Id: $Id 32 | * @since 3.4.0 33 | */ 34 | class OsTest { 35 | /** 36 | *

testUndefinedFamily.

37 | */ 38 | @Test 39 | void undefinedFamily() { 40 | assertFalse(Os.isFamily("bogus family")); 41 | } 42 | 43 | /** 44 | *

testOs.

45 | */ 46 | @Test 47 | void os() { 48 | Iterator iter = Os.getValidFamilies().iterator(); 49 | String currentFamily = null; 50 | String notCurrentFamily = null; 51 | while (iter.hasNext() && (currentFamily == null || notCurrentFamily == null)) { 52 | String fam = iter.next(); 53 | if (Os.isFamily(fam)) { 54 | currentFamily = fam; 55 | } else { 56 | notCurrentFamily = fam; 57 | } 58 | } 59 | 60 | // make sure the OS_FAMILY is set right. 61 | assertEquals(Os.OS_FAMILY, currentFamily); 62 | 63 | // check the current family and one of the others 64 | assertTrue(Os.isOs(currentFamily, null, null, null)); 65 | assertFalse(Os.isOs(notCurrentFamily, null, null, null)); 66 | 67 | // check for junk 68 | assertFalse(Os.isOs("junk", null, null, null)); 69 | 70 | // check the current name 71 | assertTrue(Os.isOs(currentFamily, Os.OS_NAME, null, null)); 72 | 73 | // check some other name 74 | assertFalse(Os.isOs(currentFamily, "myos", null, null)); 75 | 76 | // check the arch 77 | assertTrue(Os.isOs(currentFamily, Os.OS_NAME, Os.OS_ARCH, null)); 78 | assertFalse(Os.isOs(currentFamily, Os.OS_NAME, "myarch", null)); 79 | 80 | // check the version 81 | assertTrue(Os.isOs(currentFamily, Os.OS_NAME, Os.OS_ARCH, Os.OS_VERSION)); 82 | assertFalse(Os.isOs(currentFamily, Os.OS_NAME, Os.OS_ARCH, "myversion")); 83 | } 84 | 85 | /** 86 | *

testValidList.

87 | */ 88 | @Test 89 | void validList() { 90 | assertTrue(Os.isValidFamily("dos")); 91 | 92 | assertFalse(Os.isValidFamily("")); 93 | assertFalse(Os.isValidFamily(null)); 94 | assertFalse(Os.isValidFamily("something")); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/test/java/org/codehaus/plexus/util/PathToolTest.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import static org.junit.jupiter.api.Assertions.assertEquals; 22 | 23 | /** 24 | *

PathToolTest class.

25 | * 26 | * @author Vincent Siveton 27 | * @version $Id: $Id 28 | * @since 3.4.0 29 | */ 30 | class PathToolTest { 31 | /** 32 | *

testGetRelativePath.

33 | * 34 | * @throws java.lang.Exception 35 | */ 36 | @Test 37 | void getRelativePath() throws Exception { 38 | assertEquals("", PathTool.getRelativePath(null, null)); 39 | assertEquals("", PathTool.getRelativePath(null, "/usr/local/java/bin")); 40 | assertEquals("", PathTool.getRelativePath("/usr/local/", null)); 41 | assertEquals("..", PathTool.getRelativePath("/usr/local/", "/usr/local/java/bin")); 42 | assertEquals("../..", PathTool.getRelativePath("/usr/local/", "/usr/local/java/bin/java.sh")); 43 | assertEquals("", PathTool.getRelativePath("/usr/local/java/bin/java.sh", "/usr/local/")); 44 | } 45 | 46 | /** 47 | *

testGetDirectoryComponent.

48 | * 49 | * @throws java.lang.Exception 50 | */ 51 | @Test 52 | void getDirectoryComponent() throws Exception { 53 | assertEquals("", PathTool.getDirectoryComponent(null)); 54 | assertEquals("/usr/local/java", PathTool.getDirectoryComponent("/usr/local/java/bin")); 55 | assertEquals("/usr/local/java/bin", PathTool.getDirectoryComponent("/usr/local/java/bin/")); 56 | assertEquals("/usr/local/java/bin", PathTool.getDirectoryComponent("/usr/local/java/bin/java.sh")); 57 | } 58 | 59 | /** 60 | *

testCalculateLink.

61 | * 62 | */ 63 | @Test 64 | void calculateLink() { 65 | assertEquals("../../index.html", PathTool.calculateLink("/index.html", "../..")); 66 | assertEquals( 67 | "http://plexus.codehaus.org/plexus-utils/index.html", 68 | PathTool.calculateLink("http://plexus.codehaus.org/plexus-utils/index.html", "../..")); 69 | assertEquals( 70 | "../../usr/local/java/bin/java.sh", PathTool.calculateLink("/usr/local/java/bin/java.sh", "../..")); 71 | assertEquals( 72 | "/usr/local/java/bin/../index.html", PathTool.calculateLink("../index.html", "/usr/local/java/bin")); 73 | assertEquals( 74 | "http://plexus.codehaus.org/plexus-utils/../index.html", 75 | PathTool.calculateLink("../index.html", "http://plexus.codehaus.org/plexus-utils")); 76 | } 77 | 78 | /** 79 | *

testGetRelativeWebPath.

80 | * 81 | * @throws java.lang.Exception 82 | */ 83 | @Test 84 | void getRelativeWebPath() throws Exception { 85 | assertEquals("", PathTool.getRelativeWebPath(null, null)); 86 | assertEquals("", PathTool.getRelativeWebPath(null, "http://plexus.codehaus.org/")); 87 | assertEquals("", PathTool.getRelativeWebPath("http://plexus.codehaus.org/", null)); 88 | assertEquals( 89 | "plexus-utils/index.html", 90 | PathTool.getRelativeWebPath( 91 | "http://plexus.codehaus.org/", "http://plexus.codehaus.org/plexus-utils/index.html")); 92 | assertEquals( 93 | "../../", 94 | PathTool.getRelativeWebPath( 95 | "http://plexus.codehaus.org/plexus-utils/index.html", "http://plexus.codehaus.org/")); 96 | } 97 | 98 | /** 99 | *

testGetRelativeFilePath.

100 | * 101 | * @throws java.lang.Exception 102 | */ 103 | @Test 104 | void getRelativeFilePath() throws Exception { 105 | if (Os.isFamily(Os.FAMILY_WINDOWS)) { 106 | assertEquals("", PathTool.getRelativeFilePath(null, null)); 107 | assertEquals("", PathTool.getRelativeFilePath(null, "c:\\tools\\java\\bin")); 108 | assertEquals("", PathTool.getRelativeFilePath("c:\\tools\\java", null)); 109 | assertEquals("java\\bin", PathTool.getRelativeFilePath("c:\\tools", "c:\\tools\\java\\bin")); 110 | assertEquals("java\\bin\\", PathTool.getRelativeFilePath("c:\\tools", "c:\\tools\\java\\bin\\")); 111 | assertEquals("..\\..", PathTool.getRelativeFilePath("c:\\tools\\java\\bin", "c:\\tools")); 112 | assertEquals( 113 | "java\\bin\\java.exe", 114 | PathTool.getRelativeFilePath("c:\\tools\\", "c:\\tools\\java\\bin\\java.exe")); 115 | assertEquals("..\\..\\..", PathTool.getRelativeFilePath("c:\\tools\\java\\bin\\java.sh", "c:\\tools")); 116 | assertEquals("..\\bin", PathTool.getRelativeFilePath("c:\\tools", "c:\\bin")); 117 | assertEquals("..\\tools", PathTool.getRelativeFilePath("c:\\bin", "c:\\tools")); 118 | assertEquals("", PathTool.getRelativeFilePath("c:\\bin", "c:\\bin")); 119 | } else { 120 | assertEquals("", PathTool.getRelativeFilePath(null, null)); 121 | assertEquals("", PathTool.getRelativeFilePath(null, "/usr/local/java/bin")); 122 | assertEquals("", PathTool.getRelativeFilePath("/usr/local", null)); 123 | assertEquals("java/bin", PathTool.getRelativeFilePath("/usr/local", "/usr/local/java/bin")); 124 | assertEquals("java/bin/", PathTool.getRelativeFilePath("/usr/local", "/usr/local/java/bin/")); 125 | assertEquals("../../", PathTool.getRelativeFilePath("/usr/local/java/bin", "/usr/local/")); 126 | assertEquals( 127 | "java/bin/java.sh", PathTool.getRelativeFilePath("/usr/local/", "/usr/local/java/bin/java.sh")); 128 | assertEquals("../../../", PathTool.getRelativeFilePath("/usr/local/java/bin/java.sh", "/usr/local/")); 129 | assertEquals("../../bin", PathTool.getRelativeFilePath("/usr/local/", "/bin")); 130 | assertEquals("../usr/local", PathTool.getRelativeFilePath("/bin", "/usr/local")); 131 | assertEquals("", PathTool.getRelativeFilePath("/bin", "/bin")); 132 | } 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/test/java/org/codehaus/plexus/util/PerfTest.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | /* 4 | * Copyright 2011 The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | /** 22 | *

PerfTest class.

23 | * 24 | * @author herve 25 | * @version $Id: $Id 26 | * @since 3.4.0 27 | */ 28 | class PerfTest { 29 | String src = "012345578901234556789012345678901234456789012345678901234567890"; 30 | 31 | private final int oops = 100; 32 | 33 | /** 34 | *

testSubString.

35 | */ 36 | @Test 37 | void subString() { 38 | StringBuilder res = new StringBuilder(); 39 | int len = src.length(); 40 | for (int cnt = 0; cnt < oops; cnt++) { 41 | for (int i = 0; i < len - 5; i++) { 42 | res.append(src, i, i + 4); 43 | } 44 | } 45 | int i = res.length(); 46 | System.out.println("i = " + i); 47 | } 48 | 49 | /** 50 | *

testResDir.

51 | */ 52 | @Test 53 | void resDir() { 54 | StringBuilder res = new StringBuilder(); 55 | int len = src.length(); 56 | for (int cnt = 0; cnt < oops; cnt++) { 57 | for (int i = 0; i < len - 5; i++) { 58 | res.append(src, i, i + 4); 59 | } 60 | } 61 | int i = res.length(); 62 | System.out.println("i = " + i); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | import org.junit.jupiter.api.Test; 23 | 24 | import static org.junit.jupiter.api.Assertions.assertEquals; 25 | 26 | /** 27 | * This is used to test ReflectionUtils for correctness. 28 | * 29 | * @author Jesse McConnell 30 | * @version $Id:$ 31 | * @see org.codehaus.plexus.util.ReflectionUtils 32 | * @since 3.4.0 33 | */ 34 | public final class ReflectionUtilsTest { 35 | private final ReflectionUtilsTestClass testClass = new ReflectionUtilsTestClass(); 36 | 37 | /** 38 | *

testSimpleVariableAccess.

39 | * 40 | * @throws java.lang.IllegalAccessException if any. 41 | */ 42 | @Test 43 | void simpleVariableAccess() throws IllegalAccessException { 44 | assertEquals("woohoo", ReflectionUtils.getValueIncludingSuperclasses("myString", testClass)); 45 | } 46 | 47 | /** 48 | *

testComplexVariableAccess.

49 | * 50 | * @throws java.lang.IllegalAccessException if any. 51 | */ 52 | @Test 53 | void complexVariableAccess() throws IllegalAccessException { 54 | Map map = ReflectionUtils.getVariablesAndValuesIncludingSuperclasses(testClass); 55 | 56 | Map myMap = (Map) map.get("myMap"); 57 | 58 | assertEquals("myValue", myMap.get("myKey")); 59 | assertEquals("myOtherValue", myMap.get("myOtherKey")); 60 | } 61 | 62 | /** 63 | *

testSuperClassVariableAccess.

64 | * 65 | * @throws java.lang.IllegalAccessException if any. 66 | */ 67 | @Test 68 | void superClassVariableAccess() throws IllegalAccessException { 69 | assertEquals("super-duper", ReflectionUtils.getValueIncludingSuperclasses("mySuperString", testClass)); 70 | } 71 | 72 | /** 73 | *

testSettingVariableValue.

74 | * 75 | * @throws java.lang.IllegalAccessException if any. 76 | */ 77 | @Test 78 | void settingVariableValue() throws IllegalAccessException { 79 | ReflectionUtils.setVariableValueInObject(testClass, "mySettableString", "mySetString"); 80 | 81 | assertEquals("mySetString", ReflectionUtils.getValueIncludingSuperclasses("mySettableString", testClass)); 82 | 83 | ReflectionUtils.setVariableValueInObject(testClass, "myParentsSettableString", "myParentsSetString"); 84 | 85 | assertEquals( 86 | "myParentsSetString", 87 | ReflectionUtils.getValueIncludingSuperclasses("myParentsSettableString", testClass)); 88 | } 89 | 90 | private class ReflectionUtilsTestClass extends AbstractReflectionUtilsTestClass { 91 | 92 | private String myString = "woohoo"; 93 | 94 | private String mySettableString; 95 | 96 | private Map myMap = new HashMap<>(); 97 | 98 | public ReflectionUtilsTestClass() { 99 | myMap.put("myKey", "myValue"); 100 | myMap.put("myOtherKey", "myOtherValue"); 101 | } 102 | } 103 | 104 | private class AbstractReflectionUtilsTestClass { 105 | private String mySuperString = "super-duper"; 106 | 107 | private String myParentsSettableString; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.util.Vector; 20 | 21 | import org.junit.jupiter.api.AfterEach; 22 | import org.junit.jupiter.api.BeforeEach; 23 | import org.junit.jupiter.api.Test; 24 | 25 | import static org.junit.jupiter.api.Assertions.assertEquals; 26 | import static org.junit.jupiter.api.Assertions.assertNotSame; 27 | import static org.junit.jupiter.api.Assertions.assertNull; 28 | import static org.junit.jupiter.api.Assertions.assertSame; 29 | import static org.junit.jupiter.api.Assertions.assertTrue; 30 | import static org.junit.jupiter.api.Assertions.fail; 31 | 32 | /** 33 | * Created on 21/06/2003 34 | * 35 | * @author Bert van Brakel 36 | * @version $Id: $Id 37 | * @since 3.4.0 38 | */ 39 | class SweeperPoolTest { 40 | /** The pool under test */ 41 | TestObjectPool pool; 42 | 43 | /** A bunch of object to pool */ 44 | Object o1; 45 | 46 | Object o2; 47 | 48 | Object o3; 49 | 50 | Object o4; 51 | 52 | Object o5; 53 | 54 | Object o6; 55 | 56 | /** 57 | * Test the pool limits it's size, and disposes unneeded objects correctly 58 | */ 59 | @Test 60 | void maxSize() { 61 | int sweepInterval = 0; 62 | int initialCapacity = 5; 63 | int maxSize = 2; 64 | int minSize = 1; 65 | int triggerSize = 2; 66 | 67 | pool = new TestObjectPool(maxSize, minSize, initialCapacity, sweepInterval, triggerSize); 68 | 69 | Object tmp = pool.get(); 70 | assertNull(tmp, "Expected object from pool to be null"); 71 | pool.put(o1); 72 | assertEquals(1, pool.getSize(), "Expected pool to contain 1 object"); 73 | tmp = pool.get(); 74 | assertSame(tmp, o1, "Expected returned pool object to be the same as the one put in"); 75 | pool.put(o1); 76 | pool.put(o2); 77 | assertEquals(2, pool.getSize(), "Expected pool to contain 2 objects"); 78 | pool.put(o3); 79 | assertEquals(2, pool.getSize(), "Expected pool to contain only a maximum of 2 objects."); 80 | assertEquals(1, pool.testGetDisposedObjects().size(), "Expected 1 disposed pool object"); 81 | tmp = pool.testGetDisposedObjects().iterator().next(); 82 | 83 | tmp = pool.get(); 84 | assertEquals(1, pool.getSize(), "Expected pool size to be 1 after removing one object"); 85 | Object tmp2 = pool.get(); 86 | assertEquals(0, pool.getSize(), "Expected pool size to be 0 after removing 2 objects"); 87 | assertNotSame(tmp, tmp2, "Expected returned objects to be different"); 88 | } 89 | 90 | /** 91 | *

testSweepAndTrim1.

92 | */ 93 | @Test 94 | void sweepAndTrim1() { 95 | // test trigger 96 | int sweepInterval = 1; 97 | int initialCapacity = 5; 98 | int maxSize = 5; 99 | int minSize = 1; 100 | int triggerSize = 2; 101 | 102 | pool = new TestObjectPool(maxSize, minSize, initialCapacity, sweepInterval, triggerSize); 103 | pool.put(o1); 104 | pool.put(o2); 105 | pool.put(o3); 106 | pool.put(o4); 107 | // give the sweeper some time to run 108 | synchronized (this) { 109 | try { 110 | wait(2 * 1000); 111 | } catch (InterruptedException e) { 112 | fail("Unexpected exception thrown. e=" + Tracer.traceToString(e)); 113 | } 114 | } 115 | assertEquals(1, pool.getSize(), "Expected pool to only contain 1 object"); 116 | assertEquals(3, pool.testGetDisposedObjects().size(), "Expected 3 disposed objects"); 117 | } 118 | 119 | /** 120 | *

setUp.

121 | * 122 | * @throws java.lang.Exception if any. 123 | */ 124 | @BeforeEach 125 | void setUp() throws Exception { 126 | o1 = new Object(); 127 | o2 = new Object(); 128 | o3 = new Object(); 129 | o4 = new Object(); 130 | o5 = new Object(); 131 | o6 = new Object(); 132 | } 133 | 134 | /** 135 | *

tearDown.

136 | * 137 | * @throws java.lang.Exception if any. 138 | */ 139 | @AfterEach 140 | void tearDown() throws Exception { 141 | pool.dispose(); 142 | assertTrue(pool.isDisposed()); 143 | pool = null; 144 | } 145 | 146 | class TestObjectPool extends SweeperPool { 147 | private final Vector disposedObjects = new Vector<>(); 148 | 149 | public TestObjectPool(int maxSize, int minSize, int intialCapacity, int sweepInterval, int triggerSize) { 150 | super(maxSize, minSize, intialCapacity, sweepInterval, triggerSize); 151 | } 152 | 153 | public void reset() { 154 | disposedObjects.clear(); 155 | } 156 | 157 | /** 158 | * @see nz.co.bonzo.beans.castor.pool.ObjectPool#objectDisposed(java.lang.Object) 159 | */ 160 | public void objectDisposed(Object obj) { 161 | disposedObjects.add(obj); 162 | } 163 | 164 | public Vector testGetDisposedObjects() { 165 | return disposedObjects; 166 | } 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /src/test/java/org/codehaus/plexus/util/TestThreadManager.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.util.Collection; 20 | import java.util.Vector; 21 | import java.util.logging.Logger; 22 | 23 | /** 24 | * Manages a number of test threads, which notify this manager when they have completed. Allows TestCases to easily 25 | * start and manage multiple test threads. 26 | *

27 | * Created on 9/06/2003 28 | *

29 | * 30 | * @author Bert van Brakel 31 | * @version $Id: $Id 32 | * @since 3.4.0 33 | */ 34 | public class TestThreadManager { 35 | // ~ Instance fields ---------------------------------------------------------------------------- 36 | 37 | /** Test threads which have completed running */ 38 | private Collection runThreads = new Vector(); 39 | 40 | /** Test threads still needing to be run, or are currently running */ 41 | private Collection toRunThreads = new Vector(); 42 | 43 | private Logger logger = null; 44 | 45 | /** Any test threads which failed */ 46 | private Vector failedThreads = new Vector(); 47 | 48 | /** 49 | * The object to notify when all the test threads have completed. Clients use this to lock on (wait) while waiting 50 | * for the tests to complete 51 | */ 52 | private Object notify = null; 53 | 54 | // ~ Constructors ------------------------------------------------------------------------------- 55 | 56 | /** 57 | *

Constructor for TestThreadManager.

58 | * 59 | * @param notify a {@link java.lang.Object} object. 60 | */ 61 | public TestThreadManager(Object notify) { 62 | super(); 63 | this.notify = notify; 64 | } 65 | 66 | // ~ Methods ------------------------------------------------------------------------------------ 67 | 68 | /** 69 | *

Getter for the field runThreads.

70 | * 71 | * @return a {@link java.util.Collection} object. 72 | */ 73 | public Collection getRunThreads() { 74 | return runThreads; 75 | } 76 | 77 | /** 78 | *

runTestThreads.

79 | */ 80 | public void runTestThreads() { 81 | failedThreads.clear(); 82 | // use an array as the tests may run very quickly 83 | // and modify the toRunThreads vector and hence 84 | // cause a Concurrent ModificationException on an 85 | // iterator 86 | for (AbstractTestThread toRunThread : toRunThreads) { 87 | toRunThread.start(); 88 | } 89 | } 90 | 91 | /** 92 | *

getFailedTests.

93 | * 94 | * @return a {@link java.util.Collection} object. 95 | */ 96 | public Collection getFailedTests() { 97 | return failedThreads; 98 | } 99 | 100 | /** 101 | * Return the object which threads can wait on to be notified when all the test threads have completed running 102 | * 103 | * @return a {@link java.lang.Object} object. 104 | */ 105 | public Object getNotifyObject() { 106 | return notify; 107 | } 108 | 109 | /** 110 | *

hasFailedThreads.

111 | * 112 | * @return a boolean. 113 | */ 114 | public boolean hasFailedThreads() { 115 | return !failedThreads.isEmpty(); 116 | } 117 | 118 | /** 119 | * Determine if any threads are still running! 120 | * 121 | * @return DOCUMENT ME! 122 | */ 123 | public boolean isStillRunningThreads() { 124 | return !toRunThreads.isEmpty(); 125 | } 126 | 127 | /** 128 | *

Getter for the field toRunThreads.

129 | * 130 | * @return a {@link java.util.Collection} object. 131 | */ 132 | public Collection getToRunThreads() { 133 | return toRunThreads; 134 | } 135 | 136 | /** 137 | * DOCUMENT ME! 138 | */ 139 | public void clear() { 140 | toRunThreads.clear(); 141 | runThreads.clear(); 142 | failedThreads.clear(); 143 | } 144 | 145 | /* 146 | * (non-Javadoc) 147 | * @see java.util.Collection#remove(java.lang.Object) 148 | */ 149 | /** 150 | *

completed.

151 | * 152 | * @param thread a {@link org.codehaus.plexus.util.AbstractTestThread} object. 153 | */ 154 | public synchronized void completed(AbstractTestThread thread) { 155 | toRunThreads.remove(thread); 156 | runThreads.add(thread); 157 | if (thread.hasFailed()) { 158 | failedThreads.add(thread); 159 | } 160 | // wakeup thread which is waiting for the threads to complete 161 | // execution 162 | if (toRunThreads.isEmpty()) { 163 | synchronized (notify) { 164 | notify.notify(); 165 | } 166 | } 167 | } 168 | 169 | /** 170 | * Override this to add your own stuff. Called after registerThread(Object) 171 | * 172 | * @param thread DOCUMENT ME! 173 | */ 174 | public void doRegisterThread(AbstractTestThread thread) {} 175 | 176 | /** 177 | *

registerThread.

178 | * 179 | * @param thread a {@link org.codehaus.plexus.util.AbstractTestThread} object. 180 | */ 181 | public final void registerThread(AbstractTestThread thread) { 182 | thread.setThreadRegistry(this); 183 | if (toRunThreads.contains(thread) == false) { 184 | toRunThreads.add(thread); 185 | doRegisterThread(thread); 186 | } 187 | } 188 | 189 | /** 190 | * Put all the runThreads back in the que to be run again and clear the failedTest collection 191 | */ 192 | public void reset() { 193 | toRunThreads.clear(); 194 | for (AbstractTestThread runThread : runThreads) { 195 | runThread.reset(); 196 | registerThread(runThread); 197 | } 198 | 199 | runThreads.clear(); 200 | failedThreads.clear(); 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /src/test/java/org/codehaus/plexus/util/Tracer.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.io.PrintWriter; 20 | import java.io.StringWriter; 21 | 22 | /** 23 | * Convenience class to handle throwable stacktraces 24 | *

25 | * Created on 18/06/2003 26 | *

27 | * 28 | * @author Bert van Brakel 29 | * @version $Id: $Id 30 | * @since 3.4.0 31 | */ 32 | public class Tracer { 33 | 34 | /** 35 | * Constructor 36 | */ 37 | private Tracer() { 38 | super(); 39 | } 40 | 41 | /** 42 | * Return the throwable stack trace as a string 43 | * 44 | * @param t a {@link java.lang.Throwable} object. 45 | * @return a {@link java.lang.String} object. 46 | */ 47 | public static String traceToString(Throwable t) { 48 | if (t == null) { 49 | return null; 50 | } 51 | StringWriter sw = new StringWriter(); 52 | t.printStackTrace(new PrintWriter(sw)); 53 | return sw.toString(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/org/codehaus/plexus/util/WalkCollector.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.io.File; 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | class WalkCollector implements DirectoryWalkListener { 24 | public List steps; 25 | 26 | public File startingDir; 27 | 28 | public int startCount; 29 | 30 | public int finishCount; 31 | 32 | public int percentageLow; 33 | 34 | public int percentageHigh; 35 | 36 | /** 37 | *

Constructor for WalkCollector.

38 | */ 39 | public WalkCollector() { 40 | steps = new ArrayList(); 41 | startCount = 0; 42 | finishCount = 0; 43 | percentageLow = 0; 44 | percentageHigh = 0; 45 | } 46 | 47 | /** {@inheritDoc} */ 48 | public void directoryWalkStarting(File basedir) { 49 | debug("Walk Starting: " + basedir); 50 | startCount++; 51 | startingDir = basedir; 52 | } 53 | 54 | /** {@inheritDoc} */ 55 | public void directoryWalkStep(int percentage, File file) { 56 | percentageLow = Math.min(percentageLow, percentage); 57 | percentageHigh = Math.max(percentageHigh, percentage); 58 | debug("Walk Step: [" + percentage + "%] " + file); 59 | steps.add(file); 60 | } 61 | 62 | /** 63 | *

directoryWalkFinished.

64 | */ 65 | public void directoryWalkFinished() { 66 | debug("Walk Finished."); 67 | finishCount++; 68 | } 69 | 70 | /** {@inheritDoc} */ 71 | public void debug(String message) { 72 | System.out.println(message); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.cli; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.util.Arrays; 20 | import java.util.Locale; 21 | import java.util.Properties; 22 | 23 | import org.codehaus.plexus.util.Os; 24 | import org.junit.jupiter.api.Assertions; 25 | import org.junit.jupiter.api.Test; 26 | 27 | import static org.junit.jupiter.api.Assertions.assertEquals; 28 | import static org.junit.jupiter.api.Assertions.assertNotNull; 29 | import static org.junit.jupiter.api.Assertions.fail; 30 | 31 | /** 32 | *

CommandLineUtilsTest class.

33 | * 34 | * @author herve 35 | * @version $Id: $Id 36 | * @since 3.4.0 37 | */ 38 | @SuppressWarnings({"deprecation"}) 39 | class CommandLineUtilsTest { 40 | 41 | /** 42 | *

testQuoteArguments.

43 | */ 44 | @Test 45 | void quoteArguments() { 46 | Assertions.assertDoesNotThrow(() -> { 47 | String result = CommandLineUtils.quote("Hello"); 48 | System.out.println(result); 49 | assertEquals("Hello", result); 50 | result = CommandLineUtils.quote("Hello World"); 51 | System.out.println(result); 52 | assertEquals("\"Hello World\"", result); 53 | result = CommandLineUtils.quote("\"Hello World\""); 54 | System.out.println(result); 55 | assertEquals("'\"Hello World\"'", result); 56 | }); 57 | try { 58 | CommandLineUtils.quote("\"Hello 'World''"); 59 | fail(); 60 | } catch (Exception ignored) { 61 | } 62 | } 63 | 64 | /** 65 | * Tests that case-insensitive environment variables are normalized to upper case. 66 | * 67 | * @throws java.lang.Exception if any. 68 | */ 69 | @Test 70 | void getSystemEnvVarsCaseInsensitive() throws Exception { 71 | Properties vars = CommandLineUtils.getSystemEnvVars(false); 72 | for (Object o : vars.keySet()) { 73 | String variable = (String) o; 74 | assertEquals(variable.toUpperCase(Locale.ENGLISH), variable); 75 | } 76 | } 77 | 78 | /** 79 | * Tests that environment variables on Windows are normalized to upper case. Does nothing on Unix platforms. 80 | * 81 | * @throws java.lang.Exception if any. 82 | */ 83 | @Test 84 | void getSystemEnvVarsWindows() throws Exception { 85 | if (!Os.isFamily(Os.FAMILY_WINDOWS)) { 86 | return; 87 | } 88 | Properties vars = CommandLineUtils.getSystemEnvVars(); 89 | for (Object o : vars.keySet()) { 90 | String variable = (String) o; 91 | assertEquals(variable.toUpperCase(Locale.ENGLISH), variable); 92 | } 93 | } 94 | 95 | /** 96 | * Tests the splitting of a command line into distinct arguments. 97 | * 98 | * @throws java.lang.Exception if any. 99 | */ 100 | @Test 101 | void translateCommandline() throws Exception { 102 | assertCmdLineArgs(new String[] {}, null); 103 | assertCmdLineArgs(new String[] {}, ""); 104 | 105 | assertCmdLineArgs(new String[] {"foo", "bar"}, "foo bar"); 106 | assertCmdLineArgs(new String[] {"foo", "bar"}, " foo bar "); 107 | 108 | assertCmdLineArgs(new String[] {"foo", " double quotes ", "bar"}, "foo \" double quotes \" bar"); 109 | assertCmdLineArgs(new String[] {"foo", " single quotes ", "bar"}, "foo ' single quotes ' bar"); 110 | 111 | assertCmdLineArgs(new String[] {"foo", " \" ", "bar"}, "foo ' \" ' bar"); 112 | assertCmdLineArgs(new String[] {"foo", " ' ", "bar"}, "foo \" ' \" bar"); 113 | } 114 | 115 | private void assertCmdLineArgs(String[] expected, String cmdLine) throws Exception { 116 | String[] actual = CommandLineUtils.translateCommandline(cmdLine); 117 | assertNotNull(actual); 118 | assertEquals(expected.length, actual.length); 119 | assertEquals(Arrays.asList(expected), Arrays.asList(actual)); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/test/java/org/codehaus/plexus/util/cli/DefaultConsumerTest.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.cli; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | /** 22 | *

DefaultConsumerTest class.

23 | * 24 | * @author herve 25 | * @version $Id: $Id 26 | * @since 3.4.0 27 | */ 28 | class DefaultConsumerTest { 29 | /** 30 | *

testConsumeLine.

31 | * 32 | * @throws java.lang.Exception if any. 33 | */ 34 | @Test 35 | void consumeLine() throws Exception { 36 | DefaultConsumer cons = new DefaultConsumer(); 37 | cons.consumeLine("Test DefaultConsumer consumeLine"); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizerTest.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.cli; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import static org.junit.jupiter.api.Assertions.assertEquals; 22 | import static org.junit.jupiter.api.Assertions.assertFalse; 23 | import static org.junit.jupiter.api.Assertions.fail; 24 | 25 | /** 26 | *

EnhancedStringTokenizerTest class.

27 | * 28 | * @author herve 29 | * @version $Id: $Id 30 | * @since 3.4.0 31 | */ 32 | class EnhancedStringTokenizerTest { 33 | /** 34 | *

test1.

35 | */ 36 | @Test 37 | void test1() { 38 | EnhancedStringTokenizer est = new EnhancedStringTokenizer("this is a test string"); 39 | StringBuilder sb = new StringBuilder(); 40 | while (est.hasMoreTokens()) { 41 | sb.append(est.nextToken()); 42 | sb.append(" "); 43 | } 44 | assertEquals("this is a test string ", sb.toString()); 45 | } 46 | 47 | /** 48 | *

test2.

49 | */ 50 | @Test 51 | void test2() { 52 | EnhancedStringTokenizer est = new EnhancedStringTokenizer("1,,,3,,4", ","); 53 | assertEquals("1", est.nextToken(), "Token 1"); 54 | assertEquals("", est.nextToken(), "Token 2"); 55 | assertEquals("", est.nextToken(), "Token 3"); 56 | assertEquals("3", est.nextToken(), "Token 4"); 57 | assertEquals("", est.nextToken(), "Token 5"); 58 | assertEquals("4", est.nextToken(), "Token 6"); 59 | } 60 | 61 | /** 62 | *

test3.

63 | */ 64 | @Test 65 | void test3() { 66 | EnhancedStringTokenizer est = new EnhancedStringTokenizer("1,,,3,,4", ",", true); 67 | assertEquals("1", est.nextToken(), "Token 1"); 68 | assertEquals(",", est.nextToken(), "Token 2"); 69 | assertEquals("", est.nextToken(), "Token 3"); 70 | assertEquals(",", est.nextToken(), "Token 4"); 71 | assertEquals("", est.nextToken(), "Token 5"); 72 | assertEquals(",", est.nextToken(), "Token 6"); 73 | assertEquals("3", est.nextToken(), "Token 7"); 74 | assertEquals(",", est.nextToken(), "Token 8"); 75 | assertEquals("", est.nextToken(), "Token 9"); 76 | assertEquals(",", est.nextToken(), "Token 10"); 77 | assertEquals("4", est.nextToken(), "Token 11"); 78 | } 79 | 80 | /** 81 | *

testMultipleDelim.

82 | */ 83 | @Test 84 | void multipleDelim() { 85 | EnhancedStringTokenizer est = new EnhancedStringTokenizer("1 2|3|4", " |", true); 86 | assertEquals("1", est.nextToken(), "Token 1"); 87 | assertEquals(" ", est.nextToken(), "Token 2"); 88 | assertEquals("2", est.nextToken(), "Token 3"); 89 | assertEquals("|", est.nextToken(), "Token 4"); 90 | assertEquals("3", est.nextToken(), "Token 5"); 91 | assertEquals("|", est.nextToken(), "Token 6"); 92 | assertEquals("4", est.nextToken(), "Token 7"); 93 | assertFalse(est.hasMoreTokens(), "est.hasMoreTokens()"); 94 | } 95 | 96 | /** 97 | *

testEmptyString.

98 | */ 99 | @Test 100 | void emptyString() { 101 | EnhancedStringTokenizer est = new EnhancedStringTokenizer(""); 102 | assertFalse(est.hasMoreTokens(), "est.hasMoreTokens()"); 103 | try { 104 | est.nextToken(); 105 | fail(); 106 | } catch (Exception ignored) { 107 | } 108 | } 109 | 110 | /** 111 | *

testSimpleString.

112 | */ 113 | @Test 114 | void simpleString() { 115 | EnhancedStringTokenizer est = new EnhancedStringTokenizer("a "); 116 | assertEquals("a", est.nextToken(), "Token 1"); 117 | assertEquals("", est.nextToken(), "Token 2"); 118 | assertFalse(est.hasMoreTokens(), "est.hasMoreTokens()"); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.dag; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | import org.junit.jupiter.api.Test; 23 | 24 | import static org.junit.jupiter.api.Assertions.assertEquals; 25 | 26 | /** 27 | *

CycleDetectedExceptionTest class.

28 | * 29 | * @author Jason van Zyl 30 | * @version $Id: $Id 31 | * @since 3.4.0 32 | */ 33 | class CycleDetectedExceptionTest { 34 | /** 35 | *

testException.

36 | */ 37 | @Test 38 | void exception() { 39 | final List cycle = new ArrayList<>(); 40 | 41 | cycle.add("a"); 42 | 43 | cycle.add("b"); 44 | 45 | cycle.add("a"); 46 | 47 | final CycleDetectedException e = new CycleDetectedException("Cycle detected", cycle); 48 | 49 | assertEquals("Cycle detected a --> b --> a", e.getMessage()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.dag; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.util.List; 20 | 21 | import org.junit.jupiter.api.Assertions; 22 | import org.junit.jupiter.api.Test; 23 | 24 | import static org.junit.jupiter.api.Assertions.assertEquals; 25 | import static org.junit.jupiter.api.Assertions.assertFalse; 26 | import static org.junit.jupiter.api.Assertions.assertNotNull; 27 | import static org.junit.jupiter.api.Assertions.assertTrue; 28 | import static org.junit.jupiter.api.Assertions.fail; 29 | 30 | /** 31 | *

CycleDetectorTest class.

32 | * 33 | * @author Michal Maczka 34 | * @version $Id: $Id 35 | * @since 3.4.0 36 | */ 37 | class CycleDetectorTest { 38 | 39 | /** 40 | *

testCycyleDetection.

41 | */ 42 | @Test 43 | void cycyleDetection() { 44 | // No cycle 45 | // 46 | // a --> b --->c 47 | // 48 | Assertions.assertDoesNotThrow( 49 | () -> { 50 | final DAG dag1 = new DAG(); 51 | 52 | dag1.addEdge("a", "b"); 53 | 54 | dag1.addEdge("b", "c"); 55 | }, 56 | "Cycle should not be detected"); 57 | 58 | // 59 | // a --> b --->c 60 | // ^ | 61 | // | | 62 | // -----------| 63 | 64 | try { 65 | final DAG dag2 = new DAG(); 66 | 67 | dag2.addEdge("a", "b"); 68 | 69 | dag2.addEdge("b", "c"); 70 | 71 | dag2.addEdge("c", "a"); 72 | 73 | fail("Cycle should be detected"); 74 | 75 | } catch (CycleDetectedException e) { 76 | 77 | final List cycle = e.getCycle(); 78 | 79 | assertNotNull(cycle, "Cycle should be not null"); 80 | 81 | assertTrue(cycle.contains("a"), "Cycle contains 'a'"); 82 | 83 | assertTrue(cycle.contains("b"), "Cycle contains 'b'"); 84 | 85 | assertTrue(cycle.contains("c"), "Cycle contains 'c'"); 86 | } 87 | 88 | // | --> c 89 | // a --> b 90 | // | | --> d 91 | // ---------> 92 | Assertions.assertDoesNotThrow( 93 | () -> { 94 | final DAG dag3 = new DAG(); 95 | 96 | dag3.addEdge("a", "b"); 97 | 98 | dag3.addEdge("b", "c"); 99 | 100 | dag3.addEdge("b", "d"); 101 | 102 | dag3.addEdge("a", "d"); 103 | }, 104 | "Cycle should not be detected"); 105 | 106 | // ------------ 107 | // | | 108 | // V | --> c 109 | // a --> b 110 | // | | --> d 111 | // ---------> 112 | try { 113 | final DAG dag4 = new DAG(); 114 | 115 | dag4.addEdge("a", "b"); 116 | 117 | dag4.addEdge("b", "c"); 118 | 119 | dag4.addEdge("b", "d"); 120 | 121 | dag4.addEdge("a", "d"); 122 | 123 | dag4.addEdge("c", "a"); 124 | 125 | fail("Cycle should be detected"); 126 | 127 | } catch (CycleDetectedException e) { 128 | final List cycle = e.getCycle(); 129 | 130 | assertNotNull(cycle, "Cycle should be not null"); 131 | 132 | assertEquals("a", cycle.get(0), "Cycle contains 'a'"); 133 | 134 | assertEquals("b", cycle.get(1), "Cycle contains 'b'"); 135 | 136 | assertEquals("c", cycle.get(2), "Cycle contains 'c'"); 137 | 138 | assertEquals("a", cycle.get(3), "Cycle contains 'a'"); 139 | } 140 | 141 | // f --> g --> h 142 | // | 143 | // | 144 | // a --> b ---> c --> d 145 | // ^ | 146 | // | V 147 | // ------------ e 148 | 149 | final DAG dag5 = new DAG(); 150 | 151 | try { 152 | 153 | dag5.addEdge("a", "b"); 154 | 155 | dag5.addEdge("b", "c"); 156 | 157 | dag5.addEdge("b", "f"); 158 | 159 | dag5.addEdge("f", "g"); 160 | 161 | dag5.addEdge("g", "h"); 162 | 163 | dag5.addEdge("c", "d"); 164 | 165 | dag5.addEdge("d", "e"); 166 | 167 | dag5.addEdge("e", "b"); 168 | 169 | fail("Cycle should be detected"); 170 | 171 | } catch (CycleDetectedException e) { 172 | final List cycle = e.getCycle(); 173 | 174 | assertNotNull(cycle, "Cycle should be not null"); 175 | 176 | assertEquals(5, cycle.size(), "Cycle contains 5 elements"); 177 | 178 | assertEquals("b", cycle.get(0), "Cycle contains 'b'"); 179 | 180 | assertEquals("c", cycle.get(1), "Cycle contains 'c'"); 181 | 182 | assertEquals("d", cycle.get(2), "Cycle contains 'd'"); 183 | 184 | assertEquals("e", cycle.get(3), "Cycle contains 'e'"); 185 | 186 | assertEquals("b", cycle.get(4), "Cycle contains 'b'"); 187 | 188 | assertTrue(dag5.hasEdge("a", "b"), "Edge exists"); 189 | 190 | assertTrue(dag5.hasEdge("b", "c"), "Edge exists"); 191 | 192 | assertTrue(dag5.hasEdge("b", "f"), "Edge exists"); 193 | 194 | assertTrue(dag5.hasEdge("f", "g"), "Edge exists"); 195 | 196 | assertTrue(dag5.hasEdge("g", "h"), "Edge exists"); 197 | 198 | assertTrue(dag5.hasEdge("c", "d"), "Edge exists"); 199 | 200 | assertTrue(dag5.hasEdge("d", "e"), "Edge exists"); 201 | 202 | assertFalse(dag5.hasEdge("e", "b")); 203 | } 204 | } 205 | } 206 | -------------------------------------------------------------------------------- /src/test/java/org/codehaus/plexus/util/dag/DAGTest.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.dag; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | import java.util.Set; 22 | 23 | import org.junit.jupiter.api.Test; 24 | 25 | import static org.junit.jupiter.api.Assertions.assertEquals; 26 | import static org.junit.jupiter.api.Assertions.assertFalse; 27 | import static org.junit.jupiter.api.Assertions.assertTrue; 28 | 29 | /** 30 | *

DAGTest class.

31 | * 32 | * @author Michal Maczka 33 | * @version $Id: $Id 34 | * @since 3.4.0 35 | */ 36 | class DAGTest { 37 | /** 38 | *

testDAG.

39 | * 40 | * @throws org.codehaus.plexus.util.dag.CycleDetectedException if any. 41 | */ 42 | @Test 43 | void dag() throws CycleDetectedException { 44 | final DAG dag = new DAG(); 45 | 46 | dag.addVertex("a"); 47 | 48 | assertEquals(1, dag.getVertices().size()); 49 | 50 | assertEquals("a", dag.getVertex("a").getLabel()); 51 | 52 | dag.addVertex("a"); 53 | 54 | assertEquals(1, dag.getVertices().size()); 55 | 56 | assertEquals("a", dag.getVertex("a").getLabel()); 57 | 58 | dag.addVertex("b"); 59 | 60 | assertEquals(2, dag.getVertices().size()); 61 | 62 | assertFalse(dag.hasEdge("a", "b")); 63 | 64 | assertFalse(dag.hasEdge("b", "a")); 65 | 66 | final Vertex a = dag.getVertex("a"); 67 | 68 | final Vertex b = dag.getVertex("b"); 69 | 70 | assertEquals("a", a.getLabel()); 71 | 72 | assertEquals("b", b.getLabel()); 73 | 74 | dag.addEdge("a", "b"); 75 | 76 | assertTrue(a.getChildren().contains(b)); 77 | 78 | assertTrue(b.getParents().contains(a)); 79 | 80 | assertTrue(dag.hasEdge("a", "b")); 81 | 82 | assertFalse(dag.hasEdge("b", "a")); 83 | 84 | dag.addEdge("c", "d"); 85 | 86 | assertEquals(4, dag.getVertices().size()); 87 | 88 | final Vertex c = dag.getVertex("c"); 89 | 90 | final Vertex d = dag.getVertex("d"); 91 | 92 | assertEquals("a", a.getLabel()); 93 | 94 | assertEquals("b", b.getLabel()); 95 | 96 | assertEquals("c", c.getLabel()); 97 | 98 | assertEquals("d", d.getLabel()); 99 | 100 | assertFalse(dag.hasEdge("b", "a")); 101 | 102 | assertFalse(dag.hasEdge("a", "c")); 103 | 104 | assertFalse(dag.hasEdge("a", "d")); 105 | 106 | assertTrue(dag.hasEdge("c", "d")); 107 | 108 | assertFalse(dag.hasEdge("d", "c")); 109 | 110 | final Set labels = dag.getLabels(); 111 | 112 | assertEquals(4, labels.size()); 113 | 114 | assertTrue(labels.contains("a")); 115 | 116 | assertTrue(labels.contains("b")); 117 | 118 | assertTrue(labels.contains("c")); 119 | 120 | assertTrue(labels.contains("d")); 121 | 122 | dag.addEdge("a", "d"); 123 | 124 | assertTrue(a.getChildren().contains(d)); 125 | 126 | assertTrue(d.getParents().contains(a)); 127 | 128 | // "b" and "d" are children of "a" 129 | assertEquals(2, a.getChildren().size()); 130 | 131 | assertTrue(a.getChildLabels().contains("b")); 132 | 133 | assertTrue(a.getChildLabels().contains("d")); 134 | 135 | // "a" and "c" are parents of "d" 136 | assertEquals(2, d.getParents().size()); 137 | 138 | assertTrue(d.getParentLabels().contains("a")); 139 | 140 | assertTrue(d.getParentLabels().contains("c")); 141 | } 142 | 143 | /** 144 | *

testGetPredecessors.

145 | * 146 | * @throws org.codehaus.plexus.util.dag.CycleDetectedException if any. 147 | */ 148 | @Test 149 | void getPredecessors() throws CycleDetectedException { 150 | final DAG dag = new DAG(); 151 | 152 | dag.addEdge("a", "b"); 153 | 154 | // 155 | // a --> b --> c --> e 156 | // | | | 157 | // | V V 158 | // --> d <-- f --> g 159 | // result d, g, f, c, b, a 160 | 161 | // force order of nodes 162 | 163 | dag.addVertex("c"); 164 | 165 | dag.addVertex("d"); 166 | 167 | dag.addEdge("a", "b"); 168 | 169 | dag.addEdge("b", "c"); 170 | 171 | dag.addEdge("b", "d"); 172 | 173 | dag.addEdge("c", "d"); 174 | 175 | dag.addEdge("c", "e"); 176 | 177 | dag.addEdge("f", "d"); 178 | 179 | dag.addEdge("e", "f"); 180 | 181 | dag.addEdge("f", "g"); 182 | 183 | final List actual = dag.getSuccessorLabels("b"); 184 | 185 | final List expected = new ArrayList(); 186 | 187 | expected.add("d"); 188 | 189 | expected.add("g"); 190 | 191 | expected.add("f"); 192 | 193 | expected.add("e"); 194 | 195 | expected.add("c"); 196 | 197 | expected.add("b"); 198 | 199 | assertEquals(expected, actual); 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.dag; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | import org.junit.jupiter.api.Test; 23 | 24 | import static org.junit.jupiter.api.Assertions.assertEquals; 25 | 26 | /** 27 | *

TopologicalSorterTest class.

28 | * 29 | * @author Michal Maczka 30 | * @version $Id: $Id 31 | * @since 3.4.0 32 | */ 33 | class TopologicalSorterTest { 34 | /** 35 | *

testDfs.

36 | * 37 | * @throws org.codehaus.plexus.util.dag.CycleDetectedException if any. 38 | */ 39 | @Test 40 | void dfs() throws CycleDetectedException { 41 | // a --> b --->c 42 | // 43 | // result a,b,c 44 | final DAG dag1 = new DAG(); 45 | 46 | dag1.addEdge("a", "b"); 47 | 48 | dag1.addEdge("b", "c"); 49 | 50 | final List expected1 = new ArrayList<>(); 51 | 52 | expected1.add("c"); 53 | 54 | expected1.add("b"); 55 | 56 | expected1.add("a"); 57 | 58 | final List actual1 = TopologicalSorter.sort(dag1); 59 | 60 | assertEquals(expected1, actual1, "Order is different then expected"); 61 | 62 | // 63 | // a <-- b <---c 64 | // 65 | // result c, b, a 66 | final DAG dag2 = new DAG(); 67 | 68 | dag2.addVertex("a"); 69 | 70 | dag2.addVertex("b"); 71 | 72 | dag2.addVertex("c"); 73 | 74 | dag2.addEdge("b", "a"); 75 | 76 | dag2.addEdge("c", "b"); 77 | 78 | final List expected2 = new ArrayList<>(); 79 | 80 | expected2.add("a"); 81 | 82 | expected2.add("b"); 83 | 84 | expected2.add("c"); 85 | 86 | final List actual2 = TopologicalSorter.sort(dag2); 87 | 88 | assertEquals(expected2, actual2, "Order is different then expected"); 89 | 90 | // 91 | // a --> b --> c --> e 92 | // | | | 93 | // | V V 94 | // --> d <-- f --> g 95 | // result d, g, f, c, b, a 96 | final DAG dag3 = new DAG(); 97 | 98 | // force order of nodes in the graph 99 | dag3.addVertex("a"); 100 | 101 | dag3.addVertex("b"); 102 | 103 | dag3.addVertex("c"); 104 | 105 | dag3.addVertex("d"); 106 | 107 | dag3.addVertex("e"); 108 | 109 | dag3.addVertex("f"); 110 | 111 | dag3.addEdge("a", "b"); 112 | 113 | dag3.addEdge("b", "c"); 114 | 115 | dag3.addEdge("b", "d"); 116 | 117 | dag3.addEdge("c", "d"); 118 | 119 | dag3.addEdge("c", "e"); 120 | 121 | dag3.addEdge("f", "d"); 122 | 123 | dag3.addEdge("e", "f"); 124 | 125 | dag3.addEdge("f", "g"); 126 | 127 | final List expected3 = new ArrayList<>(); 128 | 129 | expected3.add("d"); 130 | 131 | expected3.add("g"); 132 | 133 | expected3.add("f"); 134 | 135 | expected3.add("e"); 136 | 137 | expected3.add("c"); 138 | 139 | expected3.add("b"); 140 | 141 | expected3.add("a"); 142 | 143 | final List actual3 = TopologicalSorter.sort(dag3); 144 | 145 | assertEquals(expected3, actual3, "Order is different then expected"); 146 | 147 | // 148 | // a --> b --> c --> e 149 | // | | | 150 | // | V V 151 | // --> d <-- f 152 | // result d, f, e, c, b, a 153 | final DAG dag4 = new DAG(); 154 | // force order of nodes in the graph 155 | 156 | dag4.addVertex("f"); 157 | 158 | dag4.addVertex("e"); 159 | 160 | dag4.addVertex("d"); 161 | 162 | dag4.addVertex("c"); 163 | 164 | dag4.addVertex("a"); 165 | 166 | dag4.addVertex("b"); 167 | 168 | dag4.addEdge("a", "b"); 169 | 170 | dag4.addEdge("b", "c"); 171 | 172 | dag4.addEdge("b", "d"); 173 | 174 | dag4.addEdge("c", "d"); 175 | 176 | dag4.addEdge("c", "e"); 177 | 178 | dag4.addEdge("f", "d"); 179 | 180 | dag4.addEdge("e", "f"); 181 | 182 | final List expected4 = new ArrayList<>(); 183 | 184 | expected4.add("d"); 185 | 186 | expected4.add("f"); 187 | 188 | expected4.add("e"); 189 | 190 | expected4.add("c"); 191 | 192 | expected4.add("b"); 193 | 194 | expected4.add("a"); 195 | 196 | final List actual4 = TopologicalSorter.sort(dag4); 197 | 198 | assertEquals(expected4, actual4, "Order is different then expected"); 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /src/test/java/org/codehaus/plexus/util/dag/VertexTest.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.dag; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import static org.junit.jupiter.api.Assertions.assertEquals; 22 | 23 | /** 24 | *

VertexTest class.

25 | * 26 | * @author Michal Maczka 27 | * @version $Id: $Id 28 | * @since 3.4.0 29 | */ 30 | class VertexTest { 31 | /** 32 | *

testVertex.

33 | */ 34 | @Test 35 | void vertex() { 36 | 37 | final Vertex vertex1 = new Vertex("a"); 38 | 39 | assertEquals("a", vertex1.getLabel()); 40 | 41 | assertEquals(0, vertex1.getChildren().size()); 42 | 43 | assertEquals(0, vertex1.getChildLabels().size()); 44 | 45 | final Vertex vertex2 = new Vertex("b"); 46 | 47 | assertEquals("b", vertex2.getLabel()); 48 | 49 | vertex1.addEdgeTo(vertex2); 50 | 51 | assertEquals(1, vertex1.getChildren().size()); 52 | 53 | assertEquals(1, vertex1.getChildLabels().size()); 54 | 55 | assertEquals(vertex2, vertex1.getChildren().get(0)); 56 | 57 | assertEquals("b", vertex1.getChildLabels().get(0)); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/org/codehaus/plexus/util/io/CachingOutputStreamTest.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.io; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.io.IOException; 20 | import java.nio.charset.StandardCharsets; 21 | import java.nio.file.Files; 22 | import java.nio.file.Path; 23 | import java.nio.file.Paths; 24 | import java.nio.file.attribute.FileTime; 25 | import java.util.Objects; 26 | 27 | import org.junit.jupiter.api.BeforeEach; 28 | import org.junit.jupiter.api.Test; 29 | 30 | import static org.junit.jupiter.api.Assertions.assertArrayEquals; 31 | import static org.junit.jupiter.api.Assertions.assertEquals; 32 | import static org.junit.jupiter.api.Assertions.assertFalse; 33 | import static org.junit.jupiter.api.Assertions.assertNotEquals; 34 | import static org.junit.jupiter.api.Assertions.assertTrue; 35 | 36 | class CachingOutputStreamTest { 37 | 38 | Path tempDir; 39 | Path checkLastModified; 40 | 41 | @BeforeEach 42 | void setup() throws IOException { 43 | Path dir = Paths.get("target/io"); 44 | Files.createDirectories(dir); 45 | tempDir = Files.createTempDirectory(dir, "temp-"); 46 | checkLastModified = tempDir.resolve(".check"); 47 | } 48 | 49 | private void waitLastModified() throws IOException, InterruptedException { 50 | Files.newOutputStream(checkLastModified).close(); 51 | FileTime lm = Files.getLastModifiedTime(checkLastModified); 52 | while (true) { 53 | Files.newOutputStream(checkLastModified).close(); 54 | FileTime nlm = Files.getLastModifiedTime(checkLastModified); 55 | if (!Objects.equals(nlm, lm)) { 56 | break; 57 | } 58 | Thread.sleep(10); 59 | } 60 | } 61 | 62 | @Test 63 | void writeNoExistingFile() throws IOException, InterruptedException { 64 | byte[] data = "Hello world!".getBytes(StandardCharsets.UTF_8); 65 | Path path = tempDir.resolve("file.txt"); 66 | assertFalse(Files.exists(path)); 67 | 68 | try (CachingOutputStream cos = new CachingOutputStream(path, 4)) { 69 | cos.write(data); 70 | } 71 | assertTrue(Files.exists(path)); 72 | byte[] read = Files.readAllBytes(path); 73 | assertArrayEquals(data, read); 74 | FileTime modified = Files.getLastModifiedTime(path); 75 | 76 | waitLastModified(); 77 | 78 | try (CachingOutputStream cos = new CachingOutputStream(path, 4)) { 79 | cos.write(data); 80 | } 81 | assertTrue(Files.exists(path)); 82 | read = Files.readAllBytes(path); 83 | assertArrayEquals(data, read); 84 | FileTime newModified = Files.getLastModifiedTime(path); 85 | assertEquals(modified, newModified); 86 | modified = newModified; 87 | 88 | waitLastModified(); 89 | 90 | // write longer data 91 | data = "Good morning!".getBytes(StandardCharsets.UTF_8); 92 | try (CachingOutputStream cos = new CachingOutputStream(path, 4)) { 93 | cos.write(data); 94 | } 95 | assertTrue(Files.exists(path)); 96 | read = Files.readAllBytes(path); 97 | assertArrayEquals(data, read); 98 | newModified = Files.getLastModifiedTime(path); 99 | assertNotEquals(modified, newModified); 100 | modified = newModified; 101 | 102 | waitLastModified(); 103 | 104 | // different data same size 105 | data = "Good mornong!".getBytes(StandardCharsets.UTF_8); 106 | try (CachingOutputStream cos = new CachingOutputStream(path, 4)) { 107 | cos.write(data); 108 | } 109 | assertTrue(Files.exists(path)); 110 | read = Files.readAllBytes(path); 111 | assertArrayEquals(data, read); 112 | newModified = Files.getLastModifiedTime(path); 113 | assertNotEquals(modified, newModified); 114 | modified = newModified; 115 | 116 | waitLastModified(); 117 | 118 | // same data but shorter 119 | data = "Good mornon".getBytes(StandardCharsets.UTF_8); 120 | try (CachingOutputStream cos = new CachingOutputStream(path, 4)) { 121 | cos.write(data); 122 | } 123 | assertTrue(Files.exists(path)); 124 | read = Files.readAllBytes(path); 125 | assertArrayEquals(data, read); 126 | newModified = Files.getLastModifiedTime(path); 127 | assertNotEquals(modified, newModified); 128 | modified = newModified; 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/test/java/org/codehaus/plexus/util/io/CachingWriterTest.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.io; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import java.io.IOException; 20 | import java.io.Writer; 21 | import java.nio.charset.StandardCharsets; 22 | import java.nio.file.Files; 23 | import java.nio.file.Path; 24 | import java.nio.file.Paths; 25 | import java.nio.file.attribute.FileTime; 26 | import java.util.Objects; 27 | 28 | import org.junit.jupiter.api.BeforeEach; 29 | import org.junit.jupiter.api.Test; 30 | 31 | import static org.junit.jupiter.api.Assertions.assertEquals; 32 | import static org.junit.jupiter.api.Assertions.assertFalse; 33 | import static org.junit.jupiter.api.Assertions.assertNotEquals; 34 | import static org.junit.jupiter.api.Assertions.assertTrue; 35 | 36 | class CachingWriterTest { 37 | 38 | Path tempDir; 39 | Path checkLastModified; 40 | 41 | @BeforeEach 42 | void setup() throws IOException { 43 | Path dir = Paths.get("target/io"); 44 | Files.createDirectories(dir); 45 | tempDir = Files.createTempDirectory(dir, "temp-"); 46 | checkLastModified = tempDir.resolve(".check"); 47 | } 48 | 49 | private void waitLastModified() throws IOException, InterruptedException { 50 | Files.newOutputStream(checkLastModified).close(); 51 | FileTime lm = Files.getLastModifiedTime(checkLastModified); 52 | while (true) { 53 | Files.newOutputStream(checkLastModified).close(); 54 | FileTime nlm = Files.getLastModifiedTime(checkLastModified); 55 | if (!Objects.equals(nlm, lm)) { 56 | break; 57 | } 58 | Thread.sleep(10); 59 | } 60 | } 61 | 62 | @Test 63 | void noOverwriteWithFlush() throws IOException, InterruptedException { 64 | String data = "Hello world!"; 65 | Path path = tempDir.resolve("file-bigger.txt"); 66 | assertFalse(Files.exists(path)); 67 | 68 | try (Writer w = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) { 69 | for (int i = 0; i < 10; i++) { 70 | w.write(data); 71 | } 72 | } 73 | FileTime modified = Files.getLastModifiedTime(path); 74 | 75 | waitLastModified(); 76 | 77 | try (Writer w = new CachingWriter(path, StandardCharsets.UTF_8)) { 78 | for (int i = 0; i < 10; i++) { 79 | w.write(data); 80 | w.flush(); 81 | } 82 | } 83 | FileTime newModified = Files.getLastModifiedTime(path); 84 | assertEquals(modified, newModified); 85 | } 86 | 87 | @Test 88 | void writeNoExistingFile() throws IOException, InterruptedException { 89 | String data = "Hello world!"; 90 | Path path = tempDir.resolve("file.txt"); 91 | assertFalse(Files.exists(path)); 92 | 93 | try (CachingWriter cos = new CachingWriter(path, StandardCharsets.UTF_8, 4)) { 94 | cos.write(data); 95 | } 96 | assertTrue(Files.exists(path)); 97 | String read = new String(Files.readAllBytes(path), StandardCharsets.UTF_8); 98 | assertEquals(data, read); 99 | FileTime modified = Files.getLastModifiedTime(path); 100 | 101 | waitLastModified(); 102 | 103 | try (CachingWriter cos = new CachingWriter(path, StandardCharsets.UTF_8, 4)) { 104 | cos.write(data); 105 | } 106 | assertTrue(Files.exists(path)); 107 | read = new String(Files.readAllBytes(path), StandardCharsets.UTF_8); 108 | assertEquals(data, read); 109 | FileTime newModified = Files.getLastModifiedTime(path); 110 | assertEquals(modified, newModified); 111 | modified = newModified; 112 | 113 | waitLastModified(); 114 | 115 | // write longer data 116 | data = "Good morning!"; 117 | try (CachingWriter cos = new CachingWriter(path, StandardCharsets.UTF_8, 4)) { 118 | cos.write(data); 119 | } 120 | assertTrue(Files.exists(path)); 121 | read = new String(Files.readAllBytes(path), StandardCharsets.UTF_8); 122 | assertEquals(data, read); 123 | newModified = Files.getLastModifiedTime(path); 124 | assertNotEquals(modified, newModified); 125 | modified = newModified; 126 | 127 | waitLastModified(); 128 | 129 | // different data same size 130 | data = "Good mornong!"; 131 | try (CachingWriter cos = new CachingWriter(path, StandardCharsets.UTF_8, 4)) { 132 | cos.write(data); 133 | } 134 | assertTrue(Files.exists(path)); 135 | read = new String(Files.readAllBytes(path), StandardCharsets.UTF_8); 136 | assertEquals(data, read); 137 | newModified = Files.getLastModifiedTime(path); 138 | assertNotEquals(modified, newModified); 139 | modified = newModified; 140 | 141 | waitLastModified(); 142 | 143 | // same data but shorter 144 | data = "Good mornon"; 145 | try (CachingWriter cos = new CachingWriter(path, StandardCharsets.UTF_8, 4)) { 146 | cos.write(data); 147 | } 148 | assertTrue(Files.exists(path)); 149 | read = new String(Files.readAllBytes(path), StandardCharsets.UTF_8); 150 | assertEquals(data, read); 151 | newModified = Files.getLastModifiedTime(path); 152 | assertNotEquals(modified, newModified); 153 | modified = newModified; 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /src/test/java/org/codehaus/plexus/util/reflection/ReflectorTest.java: -------------------------------------------------------------------------------- 1 | package org.codehaus.plexus.util.reflection; 2 | 3 | /* 4 | * Copyright The Codehaus Foundation. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import org.junit.jupiter.api.BeforeEach; 20 | import org.junit.jupiter.api.Test; 21 | 22 | import static org.junit.jupiter.api.Assertions.assertEquals; 23 | 24 | /** 25 | *

ReflectorTest class.

26 | * 27 | * @author Jörg Schaible 28 | * @version $Id: $Id 29 | * @since 3.4.0 30 | */ 31 | class ReflectorTest { 32 | private Project project; 33 | 34 | private Reflector reflector; 35 | 36 | /** 37 | *

setUp.

38 | * 39 | * @throws java.lang.Exception if any. 40 | */ 41 | @BeforeEach 42 | void setUp() throws Exception { 43 | project = new Project(); 44 | project.setModelVersion("1.0.0"); 45 | project.setVersion("42"); 46 | 47 | reflector = new Reflector(); 48 | } 49 | 50 | /** 51 | *

testObjectPropertyFromName.

52 | * 53 | * @throws java.lang.Exception if any. 54 | */ 55 | @Test 56 | void objectPropertyFromName() throws Exception { 57 | assertEquals("1.0.0", reflector.getObjectProperty(project, "modelVersion")); 58 | } 59 | 60 | /** 61 | *

testObjectPropertyFromBean.

62 | * 63 | * @throws java.lang.Exception if any. 64 | */ 65 | @Test 66 | void objectPropertyFromBean() throws Exception { 67 | assertEquals("Foo", reflector.getObjectProperty(project, "name")); 68 | } 69 | 70 | /** 71 | *

testObjectPropertyFromField.

72 | * 73 | * @throws java.lang.Exception if any. 74 | */ 75 | @Test 76 | void objectPropertyFromField() throws Exception { 77 | assertEquals("42", reflector.getObjectProperty(project, "version")); 78 | } 79 | 80 | public static class Project { 81 | private String model; 82 | 83 | private String name; 84 | 85 | private String version; 86 | 87 | public void setModelVersion(String modelVersion) { 88 | this.model = modelVersion; 89 | } 90 | 91 | public void setVersion(String version) { 92 | this.version = version; 93 | } 94 | 95 | public String modelVersion() { 96 | return model; 97 | } 98 | 99 | public String getName() { 100 | return "Foo"; 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/test/resources/dir-layout-copy/dir1/dir2/.gitignore: -------------------------------------------------------------------------------- 1 | # just here to make the directory non-empty 2 | -------------------------------------------------------------------------------- /src/test/resources/dir-layout-copy/dir1/foo.txt: -------------------------------------------------------------------------------- 1 | nothing here 2 | -------------------------------------------------------------------------------- /src/test/resources/dir-layout-copy/empty-dir/.gitignore: -------------------------------------------------------------------------------- 1 | # just here to make the directory non-empty 2 | -------------------------------------------------------------------------------- /src/test/resources/directory-scanner/foo/bar/munchy.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codehaus-plexus/plexus-utils/2d9b8b5740a65ac8f98dfefbdc244dd218b4f24a/src/test/resources/directory-scanner/foo/bar/munchy.txt -------------------------------------------------------------------------------- /src/test/resources/directorywalker/directory1/file1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codehaus-plexus/plexus-utils/2d9b8b5740a65ac8f98dfefbdc244dd218b4f24a/src/test/resources/directorywalker/directory1/file1.txt -------------------------------------------------------------------------------- /src/test/resources/directorywalker/directory2/directory21/file21.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codehaus-plexus/plexus-utils/2d9b8b5740a65ac8f98dfefbdc244dd218b4f24a/src/test/resources/directorywalker/directory2/directory21/file21.txt -------------------------------------------------------------------------------- /src/test/resources/directorywalker/directory2/file2.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codehaus-plexus/plexus-utils/2d9b8b5740a65ac8f98dfefbdc244dd218b4f24a/src/test/resources/directorywalker/directory2/file2.txt -------------------------------------------------------------------------------- /src/test/resources/directorywalker/file.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codehaus-plexus/plexus-utils/2d9b8b5740a65ac8f98dfefbdc244dd218b4f24a/src/test/resources/directorywalker/file.txt -------------------------------------------------------------------------------- /src/test/resources/symlinks/dirOnTheOutside/FileInDirOnTheOutside.txt: -------------------------------------------------------------------------------- 1 | I am on the outside... 2 | -------------------------------------------------------------------------------- /src/test/resources/symlinks/onTheOutside.txt: -------------------------------------------------------------------------------- 1 | I am on the outside of the src 2 | -------------------------------------------------------------------------------- /src/test/resources/symlinks/regen.sh: -------------------------------------------------------------------------------- 1 | rm symlinks.zip 2 | rm symlinks.tar 3 | cd src 4 | zip --symlinks ../symlinks.zip file* targetDir sym* 5 | tar -cvf ../symlinks.tar file* targetDir sym* 6 | 7 | -------------------------------------------------------------------------------- /src/test/resources/symlinks/src/aRegularDir/aRegularFile.txt: -------------------------------------------------------------------------------- 1 | I am just an ordinary file 2 | -------------------------------------------------------------------------------- /src/test/resources/symlinks/src/fileR.txt: -------------------------------------------------------------------------------- 1 | This file is a source. r r r filemode 2 | -------------------------------------------------------------------------------- /src/test/resources/symlinks/src/fileW.txt: -------------------------------------------------------------------------------- 1 | all w 2 | -------------------------------------------------------------------------------- /src/test/resources/symlinks/src/fileX.txt: -------------------------------------------------------------------------------- 1 | xxx 2 | -------------------------------------------------------------------------------- /src/test/resources/symlinks/src/symDir: -------------------------------------------------------------------------------- 1 | targetDir/ -------------------------------------------------------------------------------- /src/test/resources/symlinks/src/symLinkToDirOnTheOutside: -------------------------------------------------------------------------------- 1 | ../dirOnTheOutside/ -------------------------------------------------------------------------------- /src/test/resources/symlinks/src/symLinkToFileOnTheOutside: -------------------------------------------------------------------------------- 1 | ../onTheOutside.txt -------------------------------------------------------------------------------- /src/test/resources/symlinks/src/symR: -------------------------------------------------------------------------------- 1 | fileR.txt -------------------------------------------------------------------------------- /src/test/resources/symlinks/src/symW: -------------------------------------------------------------------------------- 1 | fileW.txt -------------------------------------------------------------------------------- /src/test/resources/symlinks/src/symX: -------------------------------------------------------------------------------- 1 | fileX.txt -------------------------------------------------------------------------------- /src/test/resources/symlinks/src/targetDir/targetFile.txt: -------------------------------------------------------------------------------- 1 | This is a target file 2 | -------------------------------------------------------------------------------- /src/test/resources/symlinks/symlinks.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codehaus-plexus/plexus-utils/2d9b8b5740a65ac8f98dfefbdc244dd218b4f24a/src/test/resources/symlinks/symlinks.tar -------------------------------------------------------------------------------- /src/test/resources/symlinks/symlinks.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codehaus-plexus/plexus-utils/2d9b8b5740a65ac8f98dfefbdc244dd218b4f24a/src/test/resources/symlinks/symlinks.zip -------------------------------------------------------------------------------- /src/test/resources/test.txt: -------------------------------------------------------------------------------- 1 | This is a test -------------------------------------------------------------------------------- /src/test/resources/test.xdoc.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Title 5 | 6 | 7 | 8 | 9 | 10 |

Paragraph 1, line 1. Paragraph 1, line 2.

11 |

Paragraph 2, line 1. Paragraph 2, line 2.

12 |
13 |

Section title

14 |
15 |

Sub-section title

16 |
17 |

Sub-sub-section title

18 |
19 |
Sub-sub-sub-section
20 |
21 |
Sub-sub-sub-sub-section
22 |
    23 |
  • List item 1.
  • 24 |
  • List item 2. 25 | 26 | 27 | 28 | 29 |

    Paragraph contained in list item 2.

    30 |
      31 |
    • Sub-list item 1.
    • 32 |
    • Sub-list item 2.
    • 33 |
    34 |
  • 35 |
  • List item 3. Force end of list:
  • 36 |
37 |
38 |
Verbatim text not contained in list item 3
39 |
40 |
    41 |
  1. Numbered item 1. 42 |
      43 |
    1. Numbered item A.
    2. 44 |
    3. Numbered item B.
    4. 45 |
    46 |
  2. 47 |
  3. Numbered item 2.
  4. 48 |
49 |

List numbering schemes: [[1]], [[a]], [[A]], [[i]], [[I]].

50 |
51 |
52 | Defined term 1 53 |
54 |
of definition list.
55 |
56 | Defined term 2 57 |
58 |
of definition list. 59 |
60 |
Verbatim text
 61 |                             in a box        
62 |
63 |
64 |
65 |

--- instead of +-- suppresses the box around verbatim text.

66 | Figure caption 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 |
Centered
cell 1,1
Left-aligned
cell 1,2
Right-aligned
cell 1,3
cell 2,1cell 2,2cell 2,3
79 |

80 | Table caption 81 |

82 |

No grid, no caption:

83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
cellcell
cellcell
93 |

Horizontal line:

94 |
95 |

New page.

96 |

97 | Italic font. Bold font. Monospaced font.

98 |

99 | Anchor. 100 | Link to Anchor. 101 | Link to http://www.pixware.fr. 102 | Link to showing alternate text. 103 | Link to Pixware home page. 104 |

105 |

Force line
break.

106 |

Non breaking space.

107 |

Escaped special characters:
108 | ~
109 | =
110 | -
111 | +
112 | *
113 | [
114 | ]
<
>
115 | {
116 | }
117 | \ 118 |

119 |

Copyright symbol: ©©©.

120 |
121 |
122 |
123 |
124 |
125 | 126 | -------------------------------------------------------------------------------- /src/test/resources/testDocument.xhtml: -------------------------------------------------------------------------------- 1 | Title

Paragraph 1, line 1. Paragraph 1, line 2.

Paragraph 2, line 1. Paragraph 2, line 2.

Section title

Sub-section title

Sub-sub-section title

Sub-sub-sub-section title
Sub-sub-sub-sub-section title
  • List item 1.
  • List item 2.

    Paragraph contained in list item 2.

    • Sub-list item 1.
    • Sub-list item 2.
  • List item 3. Force end of list:
Verbatim text not contained in list item 3
  1. Numbered item 1.
    1. Numbered item A.
    2. Numbered item B.
  2. Numbered item 2.

List numbering schemes: [[1]], [[a]], [[A]], [[i]], [[I]].

Defined term 1
of definition list.
Defined term 2
of definition list.
Verbatim text
2 |                         in a box        

--- instead of +-- suppresses the box around verbatim text.

Figure caption

Table caption
Centered
cell 1,1
Left-aligned
cell 1,2
Right-aligned
cell 1,3
cell Bold2,1cell 2,2cell 2,3

No grid, no caption:

cellcell
cellcell
headerheader
cellcell

Horizontal line:


New page.

Italic font. Bold font. Monospaced font.

Anchor. Link to Anchor. Link to http://www.pixware.fr. Link to showing alternate text. Link to Pixware home page.

Force line
break.

Non breaking space.

Escaped special characters:
~
=
-
+
*
[
]
<
>
{
}
\

Copyright symbol: ©, ©, ©.

--------------------------------------------------------------------------------