Skip to content

Commit

Permalink
remove generic type in extendpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
baisui1981 committed Dec 20, 2024
1 parent 370d1bb commit 2ca6618
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.qlangtech.tis.extension;



import net.java.sezpoz.impl.Indexer;

import javax.annotation.processing.AbstractProcessor;
Expand All @@ -37,7 +39,13 @@
import javax.tools.StandardLocation;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* 通过编译时期拦截扩展插件接口,将一些插件的元信息写入到 class compiler output目录当中去
Expand Down Expand Up @@ -81,7 +89,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
FileObject out = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT,
"", Indexer.METAINF_ANNOTATIONS + FILE_EXTENDPOINTS
);
// System.out.println("create new res:" + out.getName());
// System.out.println("create new res:" + out.getName());
try (ObjectOutputStream o = new ObjectOutputStream(out.openOutputStream())) {
o.writeObject(extensionPoints);
}
Expand Down Expand Up @@ -164,25 +172,44 @@ public Void visitDeclared(DeclaredType t, Void aVoid) {
TISExtensible extensible = t.asElement().getAnnotation(TISExtensible.class);
extendPointMatch = extensible != null;
if (extendPointMatch) {
extendPoint = t.toString();
extendPoint = parseExtendPoint(t.toString());
}
} else {
extendPoint = childtm.toString();
extendPoint = parseExtendPoint(childtm.toString());
}
// if (extendPointMatch) {
// System.out.println(t + "----------->extendPointMatch:" + extendPointMatch + "t.getTypeArguments() size:" + t.getTypeArguments().size());
// }

if (extendPointMatch) {
for (TypeMirror p : t.getTypeArguments()) {
extendPoint = String.valueOf(p);

extendPoint = parseExtendPoint(String.valueOf(p));
}
}

return null;
}
}

private static final Pattern PATTERN_EXTEND_POINT = Pattern.compile("([\\w\\.]+?)(<\\S+?>)");

public static String parseExtendPoint(String rawExtendPoint) {
Matcher matcher = PATTERN_EXTEND_POINT.matcher(rawExtendPoint);
if (matcher.matches()) {
// 需要将类型中的范型部分去掉
// :
/**
* <pre>
* 例如:
* com.qlangtech.tis.plugin.datax.common.AutoCreateTable<com.qlangtech.tis.plugin.datax.CreateTableSqlBuilder.ColWrapper>
* 转化成:
* com.qlangtech.tis.plugin.datax.common.AutoCreateTable
* <pre/>
*/
return matcher.group(1);
} else {
return rawExtendPoint;
}
}

@Override
Expand Down
36 changes: 36 additions & 0 deletions tis-plugin-sezpoz/src/test/java/TestAll.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.
*/

import com.qlangtech.tis.extension.TestTISExtendsionInterceptor;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
*
* @author: 百岁(baisui@qlangtech.com)
* @create: 2024-12-20 13:20
**/
public class TestAll extends TestCase {

public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(TestTISExtendsionInterceptor.class);
return suite;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.qlangtech.tis.extension;

import junit.framework.TestCase;

/**
* @author: 百岁(baisui@qlangtech.com)
* @create: 2024-12-20 13:15
**/
public class TestTISExtendsionInterceptor extends TestCase {
public void testParseExtendPoint() {
String rawExtendpoint = "com.qlangtech.tis.plugin.datax.common.AutoCreateTable<com.qlangtech.tis.plugin.datax.CreateTableSqlBuilder.ColWrapper>";
final String expectExtendpoint = "com.qlangtech.tis.plugin.datax.common.AutoCreateTable";
String actualExtendpoint = TISExtendsionInterceptor.parseExtendPoint(rawExtendpoint);

assertEquals(expectExtendpoint, actualExtendpoint);

actualExtendpoint = TISExtendsionInterceptor.parseExtendPoint(expectExtendpoint);
assertEquals(expectExtendpoint, actualExtendpoint);
}
}
4 changes: 2 additions & 2 deletions tis-web-config/config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ tis.datasource.type=derby
tis.datasource.dbname=tis_console_db


assemble.host=192.168.28.119
tis.host=192.168.28.119
assemble.host=192.168.28.120
tis.host=192.168.28.120



0 comments on commit 2ca6618

Please sign in to comment.