-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make system property and file operations injectable (#47)
Creates interfaces for abstracting away system property and file operations. Wrapper plugins can inject their own code for performing those operations in ways compliant to the environment/tool. See details in #48.
- Loading branch information
Showing
3 changed files
with
145 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2021 Trustin Heuiseung Lee. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package kr.motd.maven.os; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
/** | ||
* Interface exposing file operations. | ||
*/ | ||
public interface FileOperationProvider { | ||
|
||
/** | ||
* Gets a {@link InputStream} for reading the content of the file with the specified path. | ||
* | ||
* @param filePath the system-dependent file path. | ||
* @return the {@link InputStream} that can be read to get the file content. | ||
* @throws IOException if the file does not exist, is a directory rather than a regular | ||
* file, or for some other reason cannot be opened for reading. | ||
*/ | ||
InputStream readFile(String filePath) throws IOException; | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/kr/motd/maven/os/SystemPropertyOperationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2021 Trustin Heuiseung Lee. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package kr.motd.maven.os; | ||
|
||
/** | ||
* Interface exposing system property operations. | ||
*/ | ||
public interface SystemPropertyOperationProvider { | ||
|
||
/** | ||
* Gets the system property indicated by the specified name. | ||
* | ||
* @param name the name of the system property. | ||
* @return the string value of the system property, or {@code null} if there is no | ||
* property with that key. | ||
*/ | ||
String getSystemProperty(String name); | ||
|
||
/** | ||
* Gets the system property indicated by the specified name. | ||
* | ||
* @param name the name of the system property. | ||
* @param def a default value. | ||
* @return the string value of the system property, or the default value if there is | ||
* no property with that key. | ||
*/ | ||
String getSystemProperty(String name, String def); | ||
|
||
/** | ||
* Sets the system property indicated by the specified name. | ||
* | ||
* @param name the name of the system property. | ||
* @param value the value of the system property. | ||
* @return the previous value of the system property, or {@code null} if it did not have one. | ||
*/ | ||
String setSystemProperty(String name, String value); | ||
} |