forked from redhat-developer/quarkus-ls
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support multiple template root paths.
Signed-off-by: azerr <[email protected]>
- Loading branch information
1 parent
2b15e3b
commit b1f8ed2
Showing
42 changed files
with
1,276 additions
and
206 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
89 changes: 89 additions & 0 deletions
89
qute.jdt/com.redhat.qute.jdt/schema/templateRootPathProviders.exsd
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,89 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<!-- Schema file written by PDE --> | ||
<schema targetNamespace="com.redhat.qute.jdt" xmlns="http://www.w3.org/2001/XMLSchema"> | ||
<annotation> | ||
<appinfo> | ||
<meta.schema plugin="com.redhat.qute.jdt" id="templateRootPathProviders" name="Template Root Path Providers"/> | ||
</appinfo> | ||
<documentation> | ||
This extension point allows adding a template root path providers to add new templates folder to scan. | ||
</documentation> | ||
</annotation> | ||
|
||
<element name="extension"> | ||
<annotation> | ||
<appinfo> | ||
<meta.element /> | ||
</appinfo> | ||
</annotation> | ||
<complexType> | ||
<sequence minOccurs="1" maxOccurs="unbounded"> | ||
<element ref="provider"/> | ||
</sequence> | ||
<attribute name="point" type="string" use="required"> | ||
<annotation> | ||
<documentation> | ||
|
||
</documentation> | ||
</annotation> | ||
</attribute> | ||
<attribute name="id" type="string"> | ||
<annotation> | ||
<documentation> | ||
|
||
</documentation> | ||
</annotation> | ||
</attribute> | ||
<attribute name="name" type="string"> | ||
<annotation> | ||
<documentation> | ||
|
||
</documentation> | ||
<appinfo> | ||
<meta.attribute translatable="true"/> | ||
</appinfo> | ||
</annotation> | ||
</attribute> | ||
</complexType> | ||
</element> | ||
|
||
<element name="provider"> | ||
<annotation> | ||
<documentation> | ||
Template root path provider | ||
</documentation> | ||
</annotation> | ||
<complexType> | ||
<attribute name="class" type="string" use="required"> | ||
<annotation> | ||
<documentation> | ||
Name of a class that implements ITemplateRootPathProvider | ||
</documentation> | ||
<appinfo> | ||
<meta.attribute kind="java" basedOn=":com.redhat.qute.jdt.template.rootpath.ITemplateRootPathProvider"/> | ||
</appinfo> | ||
</annotation> | ||
</attribute> | ||
</complexType> | ||
</element> | ||
|
||
|
||
<annotation> | ||
<appinfo> | ||
<meta.section type="examples"/> | ||
</appinfo> | ||
<documentation> | ||
The following is an example of a resolved Java Type factory extension: | ||
|
||
<pre> | ||
<extension point="com.redhat.qute.jdt.resolvedJavaTypeFactories"> | ||
<factory class="com.redhat.qute.jdt.internal.extensions.renarde.RenardeResolvedJavaTypeFactory" /> | ||
</extension> | ||
</pre> | ||
</documentation> | ||
</annotation> | ||
|
||
|
||
|
||
|
||
</schema> |
158 changes: 158 additions & 0 deletions
158
qute.jdt/com.redhat.qute.jdt/src/main/java/com/redhat/qute/commons/FileUtils.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,158 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.redhat.qute.commons; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.File; | ||
import java.io.UnsupportedEncodingException; | ||
import java.net.URI; | ||
import java.nio.charset.Charset; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Path; | ||
|
||
/** | ||
* File utilities. | ||
* | ||
* @author Angelo ZERR | ||
* | ||
*/ | ||
public class FileUtils { | ||
|
||
private static final String FILE_SCHEME = "file"; | ||
|
||
/** | ||
* Returns true if the given uri is a file uri and false otherwise. | ||
* | ||
* @param uri the uri | ||
* | ||
* @return true if the given uri is a file uri and false otherwise. | ||
*/ | ||
public static boolean isFileURI(URI uri) { | ||
return isEmpty(uri.getScheme()) || FILE_SCHEME.equals(uri.getScheme()); | ||
} | ||
|
||
public static URI createUri(String uriString) { | ||
if (isEmpty(uriString)) { | ||
return null; | ||
} | ||
|
||
try { | ||
if (uriString.startsWith("file:/")) { | ||
String convertedUri = uriString.replace("file:///", "file:/"); //$NON-NLS-1$//$NON-NLS-2$ | ||
convertedUri = convertedUri.replace("file://", "file:/"); //$NON-NLS-1$//$NON-NLS-2$ | ||
} | ||
if (uriString.indexOf('%') != -1) { | ||
uriString = uriDecode(uriString, StandardCharsets.UTF_8); | ||
} | ||
URI uri = URI.create(uriString); | ||
if (!isFileURI(uri)) { | ||
// The uri is not a file URI, ignore it. | ||
return null; | ||
} | ||
return uri; | ||
} catch (Exception e) { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Returns the path for the given file uri and null otherwise. | ||
* | ||
* @param uriString the Uri as string. | ||
* | ||
* @return the path for the given file uri and null otherwise. | ||
*/ | ||
public static Path createPath(String uriString) { | ||
URI fileURi = createUri(uriString); | ||
if (fileURi == null) { | ||
return null; | ||
} | ||
if (fileURi.isAbsolute()) { | ||
return new File(fileURi).toPath(); | ||
} | ||
return new File(uriString).toPath(); | ||
} | ||
|
||
public static String toUri(Path path) { | ||
return path.toUri().toASCIIString(); | ||
} | ||
|
||
/** | ||
* Decode the given encoded URI component value. Based on the following rules: | ||
* <ul> | ||
* <li>Alphanumeric characters {@code "a"} through {@code "z"}, {@code "A"} | ||
* through {@code "Z"}, and {@code "0"} through {@code "9"} stay the same.</li> | ||
* <li>Special characters {@code "-"}, {@code "_"}, {@code "."}, and {@code "*"} | ||
* stay the same.</li> | ||
* <li>A sequence "{@code %<i>xy</i>}" is interpreted as a hexadecimal | ||
* representation of the character.</li> | ||
* <li>For all other characters (including those already decoded), the output is | ||
* undefined.</li> | ||
* </ul> | ||
* | ||
* @param source the encoded String | ||
* @param charset the character set | ||
* @return the decoded value | ||
* @throws IllegalArgumentException when the given source contains invalid | ||
* encoded sequences | ||
* @since 5.0 | ||
* @see java.net.URLDecoder#decode(String, String) | ||
* | ||
* This method is a copy / paste from | ||
* https://github.com/spring-projects/spring-framework/blob/67c7b80c2bed0f4f91b27d735541e9dfad8ce5b3/spring-core/src/main/java/org/springframework/util/StringUtils.java#L821 | ||
*/ | ||
private static String uriDecode(String source, Charset charset) { | ||
int length = source.length(); | ||
if (length == 0) { | ||
return source; | ||
} | ||
// Assert.notNull(charset, "Charset must not be null"); | ||
|
||
ByteArrayOutputStream baos = new ByteArrayOutputStream(length); | ||
boolean changed = false; | ||
for (int i = 0; i < length; i++) { | ||
int ch = source.charAt(i); | ||
if (ch == '%') { | ||
if (i + 2 < length) { | ||
char hex1 = source.charAt(i + 1); | ||
char hex2 = source.charAt(i + 2); | ||
int u = Character.digit(hex1, 16); | ||
int l = Character.digit(hex2, 16); | ||
if (u == -1 || l == -1) { | ||
throw new IllegalArgumentException("Invalid encoded sequence \"" + source.substring(i) + "\""); | ||
} | ||
baos.write((char) ((u << 4) + l)); | ||
i += 2; | ||
changed = true; | ||
} else { | ||
throw new IllegalArgumentException("Invalid encoded sequence \"" + source.substring(i) + "\""); | ||
} | ||
} else { | ||
baos.write(ch); | ||
} | ||
} | ||
return (changed ? copyToString(baos, charset) : source); | ||
} | ||
|
||
private static String copyToString(ByteArrayOutputStream baos, Charset charset) { | ||
try { | ||
return baos.toString(charset.name()); | ||
} catch (UnsupportedEncodingException e) { | ||
return baos.toString(); | ||
} | ||
} | ||
|
||
private static boolean isEmpty(String value) { | ||
return value == null || value.isEmpty(); | ||
} | ||
|
||
} |
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
Oops, something went wrong.