forked from gradle/gradle
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- cleaner API/DSL for creating text resources - more modular (factory methods no longer declared in ResourceHandler)
- Loading branch information
Showing
17 changed files
with
151 additions
and
91 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
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
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
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
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
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
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
55 changes: 55 additions & 0 deletions
55
...ts/core/src/main/groovy/org/gradle/api/internal/resources/DefaultTextResourceFactory.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,55 @@ | ||
/* | ||
* Copyright 2014 the original author or authors. | ||
* | ||
* 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 org.gradle.api.internal.resources; | ||
|
||
import org.gradle.api.internal.file.FileOperations; | ||
import org.gradle.api.internal.file.TemporaryFileProvider; | ||
import org.gradle.api.resources.TextResource; | ||
import org.gradle.api.resources.TextResourceFactory; | ||
|
||
import java.nio.charset.Charset; | ||
|
||
public class DefaultTextResourceFactory implements TextResourceFactory { | ||
private final FileOperations fileOperations; | ||
private final TemporaryFileProvider tempFileProvider; | ||
|
||
public DefaultTextResourceFactory(FileOperations fileOperations, TemporaryFileProvider tempFileProvider) { | ||
this.fileOperations = fileOperations; | ||
this.tempFileProvider = tempFileProvider; | ||
} | ||
|
||
public TextResource fromString(String string) { | ||
return new StringBackedTextResource(tempFileProvider, string); | ||
} | ||
|
||
public TextResource fromFile(Object file, String charset) { | ||
return new FileCollectionBackedTextResource(fileOperations.files(file), Charset.forName(charset)); | ||
} | ||
|
||
public TextResource fromFile(Object file) { | ||
return fromFile(file, Charset.defaultCharset().name()); | ||
|
||
} | ||
|
||
public TextResource fromArchiveEntry(Object archive, String entryPath, String charset) { | ||
return new FileCollectionBackedArchiveTextResource(fileOperations, fileOperations.files(archive), entryPath, Charset.forName(charset)); | ||
} | ||
|
||
public TextResource fromArchiveEntry(Object archive, String entryPath) { | ||
return fromArchiveEntry(archive, entryPath, Charset.defaultCharset().name()); | ||
} | ||
} |
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
67 changes: 67 additions & 0 deletions
67
subprojects/core/src/main/groovy/org/gradle/api/resources/TextResourceFactory.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,67 @@ | ||
/* | ||
* Copyright 2014 the original author or authors. | ||
* | ||
* 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 org.gradle.api.resources; | ||
|
||
import org.gradle.api.Incubating; | ||
|
||
/** | ||
* Creates {@code TextResource}s backed by sources such as strings, files, and archive entries. | ||
* | ||
* @since 2.2 | ||
*/ | ||
@Incubating | ||
public interface TextResourceFactory { | ||
/** | ||
* Creates a text resource backed by the given string. | ||
* | ||
* @param string a string | ||
* @return a text resource backed by the given string | ||
*/ | ||
TextResource fromString(String string); | ||
|
||
/** | ||
* Creates a text resource backed by the given file. | ||
* | ||
* @param file a text file evaluated as per {@link org.gradle.api.Project#files(Object...)} | ||
* @param charset the file's character encoding (e.g. {@code "utf-8"}) | ||
* @return a text resource backed by the given file | ||
*/ | ||
TextResource fromFile(Object file, String charset); | ||
|
||
/** | ||
* Same as {@code fromFile(file, Charset.defaultCharset())}. | ||
*/ | ||
TextResource fromFile(Object file); | ||
|
||
/** | ||
* Creates a text resource backed by the archive entry at the given path within the given archive. | ||
* The archive format is determined based on the archive's file extension. If the archive format | ||
* is not supported or cannot be determined, any attempt to access the resource will fail with an exception. | ||
* | ||
* @param archive an archive file evaluated as per {@link org.gradle.api.Project#files(Object...)} | ||
* @param entryPath the path to an archive entry | ||
* @param charset the archive entry's character encoding (e.g. {@code "utf-8"}) | ||
* | ||
* @return a text resource backed by the archive entry at the given path within the given archive | ||
*/ | ||
TextResource fromArchiveEntry(Object archive, String entryPath, String charset); | ||
|
||
/** | ||
* Same as {@code fromArchiveEntry(archive, path, Charset.defaultCharset().name())}. | ||
*/ | ||
TextResource fromArchiveEntry(Object archive, String path); | ||
} |