Browse Source

Show only php versions availble

Code cleanup
main
Vítězslav Dvořák 3 months ago
parent
commit
eb35233366
  1. 11
      build.xml
  2. 2
      manifest.mf
  3. 3
      nbproject/project.properties
  4. 14
      nbproject/project.xml
  5. 14
      pom.xml
  6. 3
      src/com/vitexsoftware/netbeans/modules/php/versionswitch/Bundle.properties
  7. 34
      src/com/vitexsoftware/netbeans/modules/php/versionswitch/PHPSwitch.java
  8. 12
      src/com/vitexsoftware/netbeans/modules/php/versionswitch/ToolbarSwitch.java

11
build.xml

@ -5,4 +5,15 @@
<project name="com.vitexsoftware.netbeans.modules.php.versionswitch" default="netbeans" basedir=".">
<description>Builds, tests, and runs the project com.vitexsoftware.netbeans.modules.php.versionswitch.</description>
<import file="nbproject/build-impl.xml"/>
<!-- target name="dist" depends="jar">
<javadoc sourcepath="${src}" destdir="${dist}/javadoc" />
<jar jarfile="${javadoc-jar}">
<fileset dir="${dist}/javadoc" />
</jar>
<jar jarfile="${sources-jar}">
<fileset dir="${src}" />
</jar>
</target -->
</project>

2
manifest.mf

@ -4,4 +4,4 @@ OpenIDE-Module: com.vitexsoftware.netbeans.modules.php.versionswitch
OpenIDE-Module-Install: com/vitexsoftware/netbeans/modules/php/versionswitch/PHPSwitch.class
OpenIDE-Module-Localizing-Bundle: com/vitexsoftware/netbeans/modules/php/versionswitch/Bundle.properties
OpenIDE-Module-Layer: com/vitexsoftware/netbeans/modules/php/versionswitch/layer.xml
OpenIDE-Module-Implementation-Version: 202101010101
OpenIDE-Module-Specification-Version: 1.12

3
nbproject/project.properties

@ -1,4 +1,5 @@
javac.source=1.8
auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml
javac.source=11
javac.compilerargs=-Xlint -Xlint:-serial
license.file=license.txt
nbm.homepage=https://github.com/VitexSoftware/netbeans-php-switcher

14
nbproject/project.xml

@ -104,6 +104,20 @@
</run-dependency>
</dependency>
</module-dependencies>
<test-dependencies>
<test-type>
<name>unit</name>
<test-dependency>
<code-name-base>org.netbeans.libs.junit4</code-name-base>
<compile-dependency/>
</test-dependency>
<test-dependency>
<code-name-base>org.netbeans.modules.nbjunit</code-name-base>
<recursive/>
<compile-dependency/>
</test-dependency>
</test-type>
</test-dependencies>
<public-packages>
<package>com.vitexsoftware.netbeans.modules.php.versionswitch</package>
</public-packages>

14
pom.xml

@ -100,6 +100,20 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>

3
src/com/vitexsoftware/netbeans/modules/php/versionswitch/Bundle.properties

@ -4,5 +4,4 @@ OpenIDE-Module-Display-Category=PHP
OpenIDE-Module-Long-Description=<img width="100" src="https://raw.githubusercontent.com/VitexSoftware/netbeans-php-switcher/main/project-logo.png"><br>Active PHP version switcher <a href="https://github.com/VitexSoftware/netbeans-php-tools ">netbeans-php-tools</a> by <a href="https://vitexsoftware.cz/">VitexSoftware</a> <br><img src="https://raw.githubusercontent.com/VitexSoftware/netbeans-php-switcher/main/screenshot.png">
Services/AutoupdateType/com_vitexsoftware_phpswitch_update_center.instance=PHPSwitch
UpdateHandler.NewModules=false
com_vitexsoftware_phpswitch_update_center=https\://vitexsoftware.com/updates.xml
#CTL_ToolbarSwitch=
CTL_ToolbarSwitch=Set PHP version

34
src/com/vitexsoftware/netbeans/modules/php/versionswitch/PHPSwitch.java

@ -7,8 +7,13 @@
package com.vitexsoftware.netbeans.modules.php.versionswitch;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
@ -22,6 +27,7 @@ import org.openide.util.Exceptions;
/**
* Main module code
*
* @author vitex
*/
@OnShowing
@ -84,6 +90,34 @@ public class PHPSwitch extends ModuleInstall implements Runnable {
return ver;
}
/**
* Search for PHP versions in system
*
* @return php versions found
*/
public static List<String> phpVersionsAvailble() {
List<String> candidates = Arrays.asList("5.6", "7.0", "7.1", "7.2", "7.3", "7.4", "8.0");
List<String> versionsFound = new ArrayList<String>();
ListIterator<String> candidatesIterator = candidates.listIterator();
while (candidatesIterator.hasNext()) {
String version = candidatesIterator.next();
File f = new File("/usr/bin/php" + version);
if (f.exists() && !f.isDirectory() && f.isFile()) {
versionsFound.add(version);
PHPSwitch.log.info("PHP version " + version + " found");
}
}
if(versionsFound.isEmpty()){
PHPSwitch.errorDialog("No /usr/bin/phpX found");
}
return versionsFound;
}
/**
* Debug level logging
*

12
src/com/vitexsoftware/netbeans/modules/php/versionswitch/ToolbarSwitch.java

@ -38,15 +38,10 @@ import org.openide.util.actions.Presenter;
id = "com.vitexsoftware.netbeans.modules.php.versionswitch.ToolbarSwitch"
)
@ActionRegistration(
iconBase = "com/vitexsoftware/netbeans/modules/php/versionswitchphpx.png",
displayName = "#CTL_ToolbarSwitch",
lazy = false
)
@ActionReference(path = "Toolbars/ToolbarPool", position = 2000)
@Messages({
"CTL_ToolbarSwitch=PHP Version",
"PHPVersions.no_version=(no PHP Version)"
})
public class ToolbarSwitch extends AbstractAction implements Presenter.Toolbar {
@ -58,10 +53,7 @@ public class ToolbarSwitch extends AbstractAction implements Presenter.Toolbar {
// }
@Override
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand() == null) {
// show popup menu
button.mouseDown(null, 30, 30);
} else {
if (e.getActionCommand() != null) {
ToolbarPool.getDefault().setConfiguration(e.getActionCommand());
setPhpVersion(e.getActionCommand());
}
@ -73,7 +65,7 @@ public class ToolbarSwitch extends AbstractAction implements Presenter.Toolbar {
if (button == null) {
final JPopupMenu popup = new JPopupMenu();
List<String> phps = Arrays.asList("5.6", "7.0", "7.1", "7.2", "7.3", "7.4", "8.0");
List<String> phps = PHPSwitch.phpVersionsAvailble();
for (String ver : phps) {
popup.add(ver).addActionListener(ToolbarSwitch.this);

Loading…
Cancel
Save