- Notifications
You must be signed in to change notification settings - Fork17
#60 - add snippets for annotations and expectations#69
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
PhilippSalvisberg merged 7 commits intoutPLSQL:masterfromPhilippSalvisberg:feature/issue_60_snippetsJul 13, 2019
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
7 commits Select commitHold shift + click to select a range
56db6e8
add snippets for utPLSQL provided by @lwasylow
PhilippSalvisberge6c4de1
rename to distinguish between utplsql and user's file
PhilippSalvisberg6ad2353
convert node to string with correct whitespace and CDATA handling
PhilippSalvisberg5c8717a
add resources for import snippet button, and confirmation dialog
PhilippSalvisberg70a076a
class to merge UtplsqlSnippets.xml with UserSnippets.xml
PhilippSalvisbergcb1551c
tests for SnippetMerger
PhilippSalvisberg1f124cc
add import snippets button
PhilippSalvisbergFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
32 changes: 31 additions & 1 deletionsqldev/src/main/java/org/utplsql/sqldev/model/XMLTools.xtend
This file contains hidden or 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
90 changes: 90 additions & 0 deletionssqldev/src/main/java/org/utplsql/sqldev/snippet/SnippetMerger.xtend
This file contains hidden or 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,90 @@ | ||
/* | ||
* Copyright 2019 Philipp Salvisberg <philipp.salvisberg@trivadis.com> | ||
* | ||
* 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.utplsql.sqldev.snippet | ||
import java.io.BufferedReader | ||
import java.io.File | ||
import java.io.IOException | ||
import java.io.InputStreamReader | ||
import java.io.StringReader | ||
import java.nio.charset.Charset | ||
import java.nio.file.Files | ||
import java.nio.file.Paths | ||
import java.util.stream.Collectors | ||
import javax.xml.parsers.DocumentBuilderFactory | ||
import oracle.dbtools.util.Resource | ||
import org.utplsql.sqldev.model.XMLTools | ||
import org.xml.sax.InputSource | ||
class SnippetMerger { | ||
val extension XMLTools xmlTools = new XMLTools | ||
File userSnippetsFile | ||
String utplsqlSnippets | ||
def getUtplsqlSnippetsAsString() throws IOException { | ||
val stream = class.getResourceAsStream("/org/utplsql/sqldev/resources/UtplsqlSnippets.xml") | ||
val reader = new BufferedReader(new InputStreamReader(stream, Charset.defaultCharset)) | ||
return reader.lines.collect(Collectors.joining(System.lineSeparator)) | ||
} | ||
new() { | ||
// works in SQL Developer only, otherwise a ExceptionInInitializerError is thrown | ||
this (new File(Resource.RAPTOR_USER.absolutePath + File.separator + "UserSnippets.xml")) | ||
} | ||
new(File file) { | ||
utplsqlSnippets = utplsqlSnippetsAsString | ||
userSnippetsFile = file | ||
} | ||
def merge() { | ||
var String result | ||
if (userSnippetsFile.exists) { | ||
// file exists, proper merge required | ||
val userSnippets = new String(Files.readAllBytes(Paths.get(userSnippetsFile.absolutePath))) | ||
val docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder() | ||
valuserSnippetsDoc = docBuilder.parse(new InputSource(new StringReader(userSnippets))) | ||
val userSnippetsGroups = userSnippetsDoc.getNodeList('''/snippets/group[not(@category="utPLSQL Annotations" or @category="utPLSQL Expectations")]''') | ||
valutplsqlSnippetsDoc = docBuilder.parse(new InputSource(new StringReader(utplsqlSnippets))) | ||
val utplsqlSnippetsGroups = utplsqlSnippetsDoc.getNodeList('''/snippets/group''') | ||
result = ''' | ||
<?xml version = '1.0' encoding = 'UTF-8'?> | ||
<snippets> | ||
«FOR i : 0 ..< userSnippetsGroups.length» | ||
«userSnippetsGroups.item(i).nodeToString("code")» | ||
«ENDFOR» | ||
«FOR i : 0 ..< utplsqlSnippetsGroups.length» | ||
«utplsqlSnippetsGroups.item(i).nodeToString("code")» | ||
«ENDFOR» | ||
</snippets> | ||
''' | ||
} else { | ||
// just copy | ||
result = utplsqlSnippets | ||
} | ||
Files.write(Paths.get(userSnippetsFile.absolutePath), result.bytes) | ||
} | ||
def getTemplate() { | ||
return utplsqlSnippets | ||
} | ||
def getFile() { | ||
return userSnippetsFile | ||
} | ||
} |
20 changes: 20 additions & 0 deletionssqldev/src/main/java/org/utplsql/sqldev/ui/preference/PreferencePanel.xtend
This file contains hidden or 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
3 changes: 3 additions & 0 deletionssqldev/src/main/resources/org/utplsql/sqldev/resources/UtplsqlResources.properties
This file contains hidden or 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
3 changes: 3 additions & 0 deletionssqldev/src/main/resources/org/utplsql/sqldev/resources/UtplsqlResources_de.properties
This file contains hidden or 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
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
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.