Skip to content

Commit

Permalink
use SPI to read version,so can read version from cse or spring cloud …
Browse files Browse the repository at this point in the history
…too.
  • Loading branch information
laijianbin authored and liubao68 committed Feb 8, 2018
1 parent 2f571d4 commit 7b99da6
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 13 deletions.
24 changes: 12 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,18 @@
<excludeFilterFile>findbugs-exclude.xml</excludeFilterFile>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
Expand All @@ -266,18 +278,6 @@
</jacocoReports>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.
*/
package org.apache.servicecomb.serviceregistry.api;

import java.util.Map;

public interface Versions {
public Map<String, String> loadVersion();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.
*/
package org.apache.servicecomb.serviceregistry.api.registry;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.ServiceLoader;

import org.apache.servicecomb.serviceregistry.api.Versions;

public class FrameworkVersions {
private static final ServiceLoader<Versions> frameworkVersions = ServiceLoader.load(Versions.class);

public static String allVersions() {
Map<String, String> versions = new HashMap<>();
Entry<String, String> entry;
StringBuffer sb = new StringBuffer();

frameworkVersions.forEach(version -> versions.putAll(version.loadVersion()));
for (Iterator<Entry<String, String>> iterator = versions.entrySet().iterator(); iterator.hasNext();) {
entry = (Entry<String, String>) iterator.next();
sb.append(entry.getKey()).append(":").append(entry.getValue())
.append(iterator.hasNext() ? ";" : "");
}
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private Microservice createMicroserviceFromDefinition(Configuration configuratio
// use default values, we can add configure item in future.
Framework framework = new Framework();
framework.setName(CONFIG_FRAMEWORK_DEFAULT_NAME);
framework.setVersion("ServiceComb:" + MicroserviceFactory.class.getPackage().getImplementationVersion());
framework.setVersion(FrameworkVersions.allVersions());
microservice.setFramework(framework);
microservice.setRegisterBy(CONFIG_DEFAULT_REGISTER_BY);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.
*/
package org.apache.servicecomb.serviceregistry.api.registry;

import java.util.HashMap;
import java.util.Map;

import org.apache.servicecomb.serviceregistry.api.Versions;

public class ServiceCombVersion implements Versions {

@Override
public Map<String, String> loadVersion() {
Map<String, String> map = new HashMap<>();
map.put("ServiceComb", this.getClass().getPackage().getImplementationVersion());

return map;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# 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.
#

org.apache.servicecomb.serviceregistry.api.registry.ServiceCombVersion
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.
*/

package org.apache.servicecomb.serviceregistry.api.registry;

import org.junit.Assert;
import org.junit.Test;

public class TestFrameworkVersions {

@Test
public void testFrameworkVersions() {
Assert.assertEquals("ServiceComb:null", FrameworkVersions.allVersions());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.
*/

package org.apache.servicecomb.serviceregistry.api.registry;

import org.junit.Assert;
import org.junit.Test;

public class TestServiceCombVersion {

@Test
public void testServiceCombVersion() {
ServiceCombVersion version = new ServiceCombVersion();
Assert.assertEquals("{ServiceComb=null}", version.loadVersion().toString());
}
}

0 comments on commit 7b99da6

Please sign in to comment.