com.intellij.openapi.util.BuildNumber Java Examples

The following examples show how to use com.intellij.openapi.util.BuildNumber. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlazeIntellijPluginDeployer.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
private static String readPluginIdFromJar(String buildNumber, File jar)
    throws ExecutionException {
  IdeaPluginDescriptor pluginDescriptor = PluginManagerCore.loadDescriptor(jar, "plugin.xml");
  if (pluginDescriptor == null) {
    return null;
  }
  if (PluginManagerCore.isIncompatible(pluginDescriptor, BuildNumber.fromString(buildNumber))) {
    throw new ExecutionException(
        String.format(
            "Plugin SDK version '%s' is incompatible with this plugin "
                + "(since: '%s', until: '%s')",
            buildNumber, pluginDescriptor.getSinceBuild(), pluginDescriptor.getUntilBuild()));
  }
  return pluginDescriptor.getPluginId().getIdString();
}
 
Example #2
Source File: FrameTitleUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static String buildTitle() {
  ApplicationInfo applicationInfo = ApplicationInfo.getInstance();

  StringBuilder builder = new StringBuilder(applicationInfo.getName());
  builder.append(' ');
  builder.append(applicationInfo.getMajorVersion());
  builder.append('.');
  builder.append(applicationInfo.getMinorVersion());

  UpdateChannel channel = UpdateSettings.getInstance().getChannel();
  if (channel != UpdateChannel.release) {
    BuildNumber buildNumber = applicationInfo.getBuild();

    builder.append(" #");
    builder.append(buildNumber);
    builder.append(' ');
    builder.append(StringUtil.capitalize(channel.name()));
  }

  if (Platform.current().isUnderRoot()) {
    builder.append(" (Administrator)");
  }
  return builder.toString();
}
 
Example #3
Source File: MacMainFrameDecorator.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void createProtocolHandler() {
  if (ourProtocolHandler == null) {
    // install uri handler
    final ID mainBundle = invoke("NSBundle", "mainBundle");
    final ID urlTypes = invoke(mainBundle, "objectForInfoDictionaryKey:", Foundation.nsString("CFBundleURLTypes"));
    final ApplicationInfo info = ApplicationInfo.getInstance();
    final BuildNumber build = info != null ? info.getBuild() : null;
    if (urlTypes.equals(ID.NIL) && build != null && !build.isSnapshot()) {
      LOG.warn("no url bundle present. \n" +
               "To use platform protocol handler to open external links specify required protocols in the mac app layout section of the build file\n" +
               "Example: args.urlSchemes = [\"your-protocol\"] will handle following links: your-protocol://open?file=file&line=line");
      return;
    }
    ourProtocolHandler = new CustomProtocolHandler();
    Application.getApplication().setOpenURIHandler(new OpenURIHandler() {
      @Override
      public void openURI(AppEvent.OpenURIEvent event) {
        ourProtocolHandler.openLink(event.getURI());
      }
    });
  }
}
 
Example #4
Source File: PluginsLoader.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void setVersionChecker() {
  PluginValidator.VALIDATOR = new PluginDescriptorVersionValidator() {
    @Override
    public boolean validateVersion(@Nonnull PluginDescriptor descriptor) {
      return !isIncompatible(descriptor);
    }

    private boolean isIncompatible(final PluginDescriptor descriptor) {
      String platformVersion = descriptor.getPlatformVersion();
      if (StringUtil.isEmpty(platformVersion)) {
        return false;
      }

      try {
        BuildNumber buildNumber = ApplicationInfo.getInstance().getBuild();
        BuildNumber pluginBuildNumber = BuildNumber.fromString(platformVersion);
        return !buildNumber.isSnapshot() && !pluginBuildNumber.isSnapshot() && !buildNumber.equals(pluginBuildNumber);
      }
      catch (RuntimeException ignored) {
      }

      return false;
    }
  };
}
 
Example #5
Source File: StringUtils.java    From CodeGen with MIT License 5 votes vote down vote up
public static String getStackTraceAsString(Throwable throwable) {
    StringWriter stringWriter = new StringWriter();
    throwable.printStackTrace(new PrintWriter(stringWriter));
    BuildNumber number = ApplicationInfo.getInstance().getBuild();
    stringWriter.append("\n").append("BuildNumber:").append(number.asString());
    return stringWriter.toString();
}
 
Example #6
Source File: BuildNumberTest.java    From CodeGen with MIT License 5 votes vote down vote up
public static void main(String[] args) {
    BuildNumber number = ApplicationInfo.getInstance().getBuild();
    // IU-171.4249.39
    System.out.println(number.asString());
    // IU
    System.out.println(number.getProductCode());
    // 171
    System.out.println(number.getBaselineVersion());
    // 171.4249.39
    System.out.println(number.asStringWithoutProductCode());
    System.out.println(number.asStringWithoutProductCodeAndSnapshot());
    // false
    System.out.println(number.isSnapshot());
}
 
Example #7
Source File: BuilderInspectionTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void testBuilderDefaultValue() {
  final BuildNumber buildNumber = ApplicationInfo.getInstance().getBuild();
  if (193 <= buildNumber.getBaselineVersion()) {
    doNamedTest(getTestName(false) + "193");
  } else {
    doTest();
  }
}
 
Example #8
Source File: SuperBuilderInspectionTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void testBuilderDefaultValue() {
  final BuildNumber buildNumber = ApplicationInfo.getInstance().getBuild();
  if (193 <= buildNumber.getBaselineVersion()) {
    doNamedTest(getTestName(false) + "193");
  } else {
    doTest();
  }
}
 
Example #9
Source File: ApiVersionAwareLightJavaCodeInsightFixtureTestCase.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void runTest() throws Throwable {

  // Minimal API Version for these tests to pass
  BuildNumber required = BuildNumber.fromString(getMinVersion());
  if (getCurrentVersion().compareTo(required) >= 0) {
    super.runTest();
  }
}
 
Example #10
Source File: ApplicationInfo.java    From consulo with Apache License 2.0 5 votes vote down vote up
private ApplicationInfo() {
  String jarPathForClass = PathUtil.getJarPathForClass(Application.class);

  try (JarFile jarFile = new JarFile(jarPathForClass)) {
    Manifest manifest = jarFile.getManifest();

    Attributes attributes = manifest.getMainAttributes();

    String buildNumber = attributes.getValue("Consulo-Build-Number");
    if (buildNumber != null) {
      myBuild = BuildNumber.fromString(buildNumber);
    }

    // yyyyMMddHHmm
    String buildDate = attributes.getValue("Consulo-Build-Date");
    if (buildDate != null) {
      myBuildDate = parseDate(buildDate);
    }
  }
  catch (Throwable e) {
    Logger.getInstance(ApplicationInfo.class).error(e);
  }

  if (myBuild == null) {
    myBuild = BuildNumber.fallback();
  }

  if (myBuildDate == null) {
    myBuildDate = Calendar.getInstance();
  }
}
 
Example #11
Source File: BlazeTestSystemPropertiesRule.java    From intellij with Apache License 2.0 4 votes vote down vote up
/** Sets up the necessary system properties for running IntelliJ tests via blaze/bazel. */
private static void configureSystemProperties() throws IOException {
  File sandbox = new File(TestUtils.getTmpDirFile(), "_intellij_test_sandbox");

  setSandboxPath("idea.home.path", new File(sandbox, "home"));
  setSandboxPath("idea.config.path", new File(sandbox, "config"));
  setSandboxPath("idea.system.path", new File(sandbox, "system"));

  setSandboxPath("java.util.prefs.userRoot", new File(sandbox, "userRoot"));
  setSandboxPath("java.util.prefs.systemRoot", new File(sandbox, "systemRoot"));

  setIfEmpty("idea.classpath.index.enabled", "false");

  // Some plugins have a since-build and until-build restriction, so we need
  // to update the build number here
  String buildNumber = readApiVersionNumber();
  if (buildNumber == null) {
    buildNumber = BuildNumber.currentVersion().asString();
  }
  setIfEmpty("idea.plugins.compatible.build", buildNumber);
  setIfEmpty(PlatformUtils.PLATFORM_PREFIX_KEY, determinePlatformPrefix(buildNumber));

  // Tests fail if they access files outside of the project roots and other system directories.
  // Ensure runfiles and platform api are whitelisted.
  VfsRootAccess.allowRootAccess(RUNFILES_PATH);
  String platformApi = getPlatformApiPath();
  if (platformApi != null) {
    VfsRootAccess.allowRootAccess(platformApi);
  }

  List<String> pluginJars = Lists.newArrayList();
  try {
    Enumeration<URL> urls =
        BlazeTestSystemPropertiesRule.class.getClassLoader().getResources("META-INF/plugin.xml");
    while (urls.hasMoreElements()) {
      URL url = urls.nextElement();
      addArchiveFile(url, pluginJars);
    }
  } catch (IOException e) {
    System.err.println("Cannot find plugin.xml resources");
    e.printStackTrace();
  }

  setIfEmpty("idea.plugins.path", Joiner.on(File.pathSeparator).join(pluginJars));
}
 
Example #12
Source File: ApiVersionAwareLightJavaCodeInsightFixtureTestCase.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private BuildNumber getCurrentVersion() {
  return ApplicationInfo.getInstance().getBuild();
}
 
Example #13
Source File: ApplicationInfo.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public BuildNumber getBuild() {
  return myBuild;
}