-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
132 additions
and
2 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
37 changes: 37 additions & 0 deletions
37
plugin-maven/src/main/java/com/diffplug/spotless/maven/sql/DBeaver.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,37 @@ | ||
/* | ||
* Copyright 2020 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.maven.sql; | ||
|
||
import java.util.Collections; | ||
import java.util.Optional; | ||
|
||
import org.apache.maven.plugins.annotations.Parameter; | ||
|
||
import com.diffplug.spotless.FormatterStep; | ||
import com.diffplug.spotless.maven.FormatterStepConfig; | ||
import com.diffplug.spotless.maven.FormatterStepFactory; | ||
import com.diffplug.spotless.sql.DBeaverSQLFormatterStep; | ||
|
||
public class DBeaver implements FormatterStepFactory { | ||
|
||
@Parameter | ||
private String configFile; | ||
|
||
@Override | ||
public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { | ||
return DBeaverSQLFormatterStep.create(Optional.ofNullable(configFile).map(c -> stepConfig.getFileLocator().locateFile(c)).map(Collections::singleton).orElseGet(Collections::emptySet)); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
plugin-maven/src/main/java/com/diffplug/spotless/maven/sql/Sql.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 2020 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.maven.sql; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
import com.diffplug.spotless.maven.FormatterFactory; | ||
|
||
/** | ||
* A {@link FormatterFactory} implementation that corresponds to {@code <dbeaver>...</dbeaver>} configuration element. | ||
* <p> | ||
* It defines a formatter for sql source files. | ||
*/ | ||
public class Sql extends FormatterFactory { | ||
private static final String LICENSE_HEADER_DELIMITER = null; | ||
|
||
@Override | ||
public Set<String> defaultIncludes() { | ||
return Collections.emptySet(); | ||
} | ||
|
||
@Override | ||
public String licenseHeaderDelimiter() { | ||
return LICENSE_HEADER_DELIMITER; | ||
} | ||
|
||
public void addDbeaver(DBeaver dbeaver) { | ||
addStepFactory(dbeaver); | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
plugin-maven/src/test/java/com/diffplug/spotless/maven/sql/SqlTest.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-2020 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.maven.sql; | ||
|
||
import org.junit.Test; | ||
|
||
import com.diffplug.spotless.maven.MavenIntegrationHarness; | ||
|
||
public class SqlTest extends MavenIntegrationHarness { | ||
@Test | ||
public void testDbeaverWithDefaultConfig() throws Exception { | ||
writePomWithSqlSteps("<dbeaver/>"); | ||
|
||
setFile("src/main/resources/aFolder/create.sql").toResource("sql/dbeaver/create.dirty"); | ||
mavenRunner().withArguments("spotless:apply").runNoError(); | ||
assertFile("src/main/resources/aFolder/create.sql").sameAsResource("sql/dbeaver/create.clean"); | ||
} | ||
|
||
@Test | ||
public void testDbeaverWithAlternativeConfig() throws Exception { | ||
writePomWithSqlSteps("<dbeaver><configFile>myConfig.properties</configFile></dbeaver>"); | ||
setFile("myConfig.properties").toResource("sql/dbeaver/sqlConfig2.properties"); | ||
|
||
setFile("src/main/resources/aFolder/create.sql").toResource("sql/dbeaver/create.dirty"); | ||
mavenRunner().withArguments("spotless:apply").runNoError(); | ||
assertFile("src/main/resources/aFolder/create.sql").sameAsResource("sql/dbeaver/create.clean.alternative"); | ||
} | ||
} |