-
Notifications
You must be signed in to change notification settings - Fork 460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Html/JS/Json integration #315
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e9499ae
Provision of HTML, JS, JSON extensions and corresponding Eclipse-WTP.
fvgh 1b4e8d3
Merge remote-tracking branch 'origin' into html_js_json_integration
fvgh b50340e
Updated change logs.
fvgh 1fd44df
Merge branch 'master' into html_js_json_integration
fvgh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
44 changes: 44 additions & 0 deletions
44
lib/src/main/java/com/diffplug/spotless/html/HtmlDefaults.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,44 @@ | ||
/* | ||
* Copyright 2016 DiffPlug | ||
* | ||
* 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 com.diffplug.spotless.html; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import com.diffplug.spotless.xml.XmlDefaults; | ||
|
||
/** Common utilities for HTML */ | ||
public class HtmlDefaults { | ||
//Prevent instantiation | ||
private HtmlDefaults() {}; | ||
|
||
/** | ||
* Filter based on Eclipse-WTP <code>org.eclipse.core.contenttype.contentTypes</code> | ||
* extension <code>org.eclipse.wst.html.core.internal</code>. | ||
*/ | ||
public static final List<String> FILE_FILTER = Collections.unmodifiableList( | ||
Arrays.asList("html", "htm", "xhtml", "htpl", "wml", "shtml", "shtm") | ||
.stream().map(s -> { | ||
return "**/*." + s; | ||
}).collect(Collectors.toList())); | ||
|
||
/** | ||
* XML delimiter is also valid for HTML. | ||
*/ | ||
public static final String DELIMITER_EXPR = XmlDefaults.DELIMITER_EXPR; | ||
} |
7 changes: 7 additions & 0 deletions
7
lib/src/main/java/com/diffplug/spotless/html/package-info.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,7 @@ | ||
@ParametersAreNonnullByDefault | ||
@ReturnValuesAreNonnullByDefault | ||
package com.diffplug.spotless.html; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; | ||
|
||
import com.diffplug.spotless.annotations.ReturnValuesAreNonnullByDefault; |
39 changes: 39 additions & 0 deletions
39
lib/src/main/java/com/diffplug/spotless/js/JsDefaults.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,39 @@ | ||
/* | ||
* Copyright 2016 DiffPlug | ||
* | ||
* 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 com.diffplug.spotless.js; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** Common utilities for JavaScript */ | ||
public class JsDefaults { | ||
//Prevent instantiation | ||
private JsDefaults() {}; | ||
|
||
/** | ||
* Filter based on Eclipse-WTP <code>org.eclipse.core.contenttype.contentTypes</code> | ||
* extension <code>org.eclipse.wst.jsdt.core</code>. | ||
*/ | ||
public static final List<String> FILE_FILTER = Collections.unmodifiableList( | ||
Arrays.asList("**/*.js")); | ||
|
||
/** | ||
* Valid JS should start with variable/function definitions, closures or no-ops. | ||
* Initial comment (one or multi-line) is considered header. | ||
*/ | ||
public static final String DELIMITER_EXPR = "[A-Za-z\\{;]+"; | ||
} |
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,7 @@ | ||
@ParametersAreNonnullByDefault | ||
@ReturnValuesAreNonnullByDefault | ||
package com.diffplug.spotless.js; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; | ||
|
||
import com.diffplug.spotless.annotations.ReturnValuesAreNonnullByDefault; |
41 changes: 41 additions & 0 deletions
41
lib/src/main/java/com/diffplug/spotless/json/JsonDefaults.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,41 @@ | ||
/* | ||
* Copyright 2016 DiffPlug | ||
* | ||
* 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 com.diffplug.spotless.json; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** Common utilities for Json */ | ||
public class JsonDefaults { | ||
//Prevent instantiation | ||
private JsonDefaults() {}; | ||
|
||
/** | ||
* Filter based on Eclipse-WTP <code>org.eclipse.core.contenttype.contentTypes</code> | ||
* extension <code>org.eclipse.wst.json.core</code>. | ||
*/ | ||
public static final List<String> FILE_FILTER = Collections.unmodifiableList( | ||
Arrays.asList("**/*.json")); | ||
|
||
/** | ||
* JSON itself does not accept comments. However, commenting JSON | ||
* sources is good practice and projects like JSON.minify allow commenting. | ||
* Hence also headers can be supported. Everything before the first object | ||
* is considered to be part of the header. | ||
*/ | ||
public static final String DELIMITER_EXPR = "\\{"; | ||
} |
7 changes: 7 additions & 0 deletions
7
lib/src/main/java/com/diffplug/spotless/json/package-info.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,7 @@ | ||
@ParametersAreNonnullByDefault | ||
@ReturnValuesAreNonnullByDefault | ||
package com.diffplug.spotless.json; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; | ||
|
||
import com.diffplug.spotless.annotations.ReturnValuesAreNonnullByDefault; |
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
76 changes: 76 additions & 0 deletions
76
plugin-gradle/src/main/java/com/diffplug/gradle/spotless/HtmlExtension.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,76 @@ | ||
/* | ||
* Copyright 2016 DiffPlug | ||
* | ||
* 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 com.diffplug.gradle.spotless; | ||
|
||
import static com.diffplug.gradle.spotless.PluginGradlePreconditions.requireElementsNonNull; | ||
|
||
import org.gradle.api.Project; | ||
|
||
import com.diffplug.spotless.extra.EclipseBasedStepBuilder; | ||
import com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep; | ||
import com.diffplug.spotless.html.HtmlDefaults; | ||
|
||
public class HtmlExtension extends FormatExtension implements HasBuiltinDelimiterForLicense { | ||
static final String NAME = "html"; | ||
|
||
public HtmlExtension(SpotlessExtension rootExtension) { | ||
super(rootExtension); | ||
} | ||
|
||
public EclipseConfig eclipse() { | ||
return new EclipseConfig(EclipseWtpFormatterStep.defaultVersion()); | ||
} | ||
|
||
public EclipseConfig eclipse(String version) { | ||
return new EclipseConfig(version); | ||
} | ||
|
||
public class EclipseConfig { | ||
private final EclipseBasedStepBuilder builder; | ||
|
||
EclipseConfig(String version) { | ||
builder = EclipseWtpFormatterStep.createHtmlBuilder(GradleProvisioner.fromProject(getProject())); | ||
builder.setVersion(version); | ||
addStep(builder.build()); | ||
} | ||
|
||
public void configFile(Object... configFiles) { | ||
requireElementsNonNull(configFiles); | ||
Project project = getProject(); | ||
builder.setPreferences(project.files(configFiles).getFiles()); | ||
replaceStep(builder.build()); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
protected void setupTask(SpotlessTask task) { | ||
if (target == null) { | ||
target(HtmlDefaults.FILE_FILTER.toArray()); | ||
} | ||
super.setupTask(task); | ||
} | ||
|
||
@Override | ||
public LicenseHeaderConfig licenseHeader(String licenseHeader) { | ||
return licenseHeader(licenseHeader, HtmlDefaults.DELIMITER_EXPR); | ||
} | ||
|
||
@Override | ||
public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { | ||
return licenseHeaderFile(licenseHeaderFile, HtmlDefaults.DELIMITER_EXPR); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For all of these
XxxDefaults
classes, it would be better if their constants werepublic static String delimiterExpr() {}
rather thanpublic static final String DELIMITER_EXPR = ...
. See https://wiki.sei.cmu.edu/confluence/display/java/DCL59-J.+Do+not+apply+public+final+to+constants+whose+value+might+change+in+later+releases for details.We've had to change quite a few of our DELIMITER_EXPR so far, I'd expect these might need to be revised in the future as well...