├── .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 | [](https://github.com/codehaus-plexus/plexus-utils/actions)
5 | [](https://search.maven.org/artifact/org.codehaus.plexus/plexus-utils)
6 | [](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 | *
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 | *
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 |
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 | *
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 | *
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 | *